Improved safety handling of bad PHP interpretor releases.
[fa-stable.git] / reporting / includes / html_entity_decode_php4.php
index 1ecad710f053238c35af49248154a976780ae129..b3ff4199e0cb781da78366b563ea2348f55ddb07 100644 (file)
@@ -332,8 +332,18 @@ function html_entity_decode_php4($text_to_convert) {
                "&lt;" => "<"
        );
        $return_text = strtr($text_to_convert, $htmlentities_table);
-       $return_text = preg_replace('~&#x([0-9a-f]+);~ei', 'code_to_utf8(hexdec("\\1"))', $return_text);
-       $return_text = preg_replace('~&#([0-9]+);~e', 'code_to_utf8(\\1)', $return_text);
+       
+       // 07.11.2014, from php 5.3.0 fixed deprecated preg_replace with the /e flag. Joe
+       if (version_compare(PHP_VERSION, '5.3.0') >= 0 && function_exists("preg_replace_callback"))
+       { 
+               $return_text = preg_replace_callback('~&#x([0-9a-f]+);~i', function ($m){ return chr(hexdec($m[1]));}, $return_text);
+               $return_text = preg_replace_callback('~&#([0-9]+);~', function ($m){ return chr($m[1]);}, $return_text);
+       }
+       else
+       {
+               $return_text = preg_replace('~&#x([0-9a-f]+);~ei', 'code_to_utf8(hexdec("\\1"))', $return_text);
+               $return_text = preg_replace('~&#([0-9]+);~e', 'code_to_utf8(\\1)', $return_text);
+       }
        return $return_text;
 }