本文介绍了函数preg_replace e/修饰符的替代方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都知道如何使用preg_replace和e/修饰符更改此功能e/修饰符将被贬值.
Anybody knows how to change this function with preg_replace and the e/ modifierThe e/ modifier will be depreciated.
function charset_decode_utf_8 ($string) {
/* Only do the slow convert if there are 8-bit characters */
/* avoid using 0xA0 (\240) in ereg ranges. RH73 does not like that */
if (! preg_match("/[\200-\237]/", $string) and ! preg_match("/[\241-\377]/", $string))
return $string;
// decode three byte unicode characters
$string = preg_replace("/([\340-\357])([\200-\277])([\200-\277])/e",
"'&#'.((ord('\\1')-224)*4096 + (ord('\\2')-128)*64 + (ord('\\3')-128)).';'",
$string);
// decode two byte unicode characters
$string = preg_replace("/([\300-\337])([\200-\277])/e",
"'&#'.((ord('\\1')-192)*64+(ord('\\2')-128)).';'",
$string);
return $string;
}
推荐答案
<?php
$string = preg_replace_callback("/([\340-\357])([\200-\277])([\200-\277])/",
function($arr) {
$val = (ord($arr[1]) - 224) * 4096
+ (ord($arr[2]) - 128) * 64
+ (ord($arr[3]) - 128);
return "&#" . $val . ";";
}, $string);
$string = preg_replace_callback("/([\300-\337])([\200-\277])/",
function($arr)
{
$val = (ord($arr[1]) - 192) * 64 + ord($arr[2]) - 128;
return "&#" . $val . ";";
}, $string);
这篇关于函数preg_replace e/修饰符的替代方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!