preg_replace_callback()

Started by Mahle, March 07, 2016, 04:17:01 PM

Previous topic - Next topic

Mahle

Hi All,

I am kind of new to php, but have some programming background.
I was asked by a friend to look into some error message she was getting on her website. Here is the error msg:
"Message: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead"

So after some digging n the code, as you all might be aware, the use pf preg_replace() needs to be replaced by preg_replace_callback().
I have pasted the parts of the code that are relevant.

I guess I am not sure how the use the callback function at this point, as I am still working to learn the php syntax.
Any help or hint would be greatly appreciated.

Regards



if(!function_exists('strcode2utf')){
  function strcode2utf($str,$lo=true) {
   //converts all the &#nnn; and &#xhhh; in a string to Unicode
   if ($lo) { $lo = 1; } else { $lo = 0; }
   
   $str = preg_replace('/\&\#([0-9]+)\;/me', "code2utf('\\1',{$lo})",$str);
   $str = preg_replace('/\&\#x([0-9a-fA-F]+)\;/me', "codeHex2utf('\\1',{$lo})",$str);
   
   return $str;
  }


and:

if(!function_exists('code2utf')){
  function code2utf($num,$lo=true){
   //Returns the utf string corresponding to the unicode value
   if ($num<128) {
      if ($lo) return chr($num);
      else return '&#'.$num.';';   // i.e. no change
   }
   if ($num<2048) return chr(($num>>6)+192).chr(($num&63)+128);
   if ($num<65536) return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128);
   if ($num<2097152) return chr(($num>>18)+240).chr((($num>>12)&63)+128).chr((($num>>6)&63)+128) .chr(($num&63)+128);
   return '?';
  }
}


if(!function_exists('codeHex2utf')){
  function codeHex2utf($hex,$lo=true){
   $num = hexdec($hex);
   if (($num<128) && !$lo) return '&#x'.$hex.';';   // i.e. no change
   return code2utf($num,$lo);
  }
}

Illori

which version of SMF is being used?

Mahle

cPanel indicates: PHP version 5.5.31

Illori

i asked for SMF version not php.

live627

None. That's not code from SMF.

I'll take a look in a bit.

topic moved

Advertisement: