Preg_replace deprecated - Stack Of Codes

Breaking

Monday, 27 November 2017

Preg_replace deprecated


preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead

i'm not sure but it seems the entity_decode method in core/security is a very legacy fix for a pre php 5 bug in html_entity_decode. is this still needed?

A quick fix i used is replacing the latter two with replace_callback as mention in this stackoverflow article (1).

// Numeric Entities

// $str = preg_replace('~&#x(0*[0-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str);
// $str = preg_replace('~&#([0-9]{2,4});{0,1}~e', 'chr(\\1)', $str);

$str = preg_replace_callback('~&#x(0*[0-9a-f]{2,5});{0,1}~i',
  create_function ('$matches', 'return chr(hexdec($matches[1]));'), $str);

$str = preg_replace_callback('~&#([0-9]{2,4});{0,1}~',
  create_function ('$matches', 'return chr($matches[1]);'), $str);
  

No comments:

Post a Comment

Topics

PHP (27) CodeIgniter (22) SQL (4) Facebook (3) HTML (3) Blogger (2) Constructor (2) Destructor (2) Google (2) Aadhaar (1) Agent (1) Browser (1) CSS (1) Cakephp (1) Constants (1) How to (1) India (1) Ip address (1) JS (1) Jquery (1) Meta Tags (1) Robots (1) Scraping Data (1) escape_str (1) htaccess (1) iS mobile (1) javascript (1) mysqli (1)