Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
替换php字符串中unicode字符的最佳方法是什么?_Php_Unicode - Fatal编程技术网

替换php字符串中unicode字符的最佳方法是什么?

替换php字符串中unicode字符的最佳方法是什么?,php,unicode,Php,Unicode,我有一些奇怪的字符出现在生产数据库中。我要替换的字符串是\u00fc\u00be\u008c\u00a3\u00a4\u00bc 这是失败的 $column = str_replace('\u00fc\u00be\u008c\u00a3\u00a4\u00bc', "'", $column); 这是有效的 $column = str_replace('ü¾£¤¼',"'",$column) ; 在不复制解码文本的情况下,替换PHP字符串中的unicode字符的最佳方法是什么?遵循前面的指导,

我有一些奇怪的字符出现在生产数据库中。我要替换的字符串是\u00fc\u00be\u008c\u00a3\u00a4\u00bc

这是失败的

$column = str_replace('\u00fc\u00be\u008c\u00a3\u00a4\u00bc', "'", $column);
这是有效的

$column = str_replace('ü¾£¤¼',"'",$column) ;

在不复制解码文本的情况下,替换PHP字符串中的unicode字符的最佳方法是什么?

遵循前面的指导,我使用json_decode来翻译unicode,这很有效

$unicode = json_decode("\u00fc\u00be\u008c\u00a3\u00a4\u00bc") ;
$column = str_replace($unicode, "'", urldecode($row[$columnIndex]));

这只是一个猜测,因为我没有地方测试这个atm,但请尝试在第一个示例中使用双引号。单引号将其视为文字。您应该查看[编辑:问题涉及单个字符,但相同的原则适用于字符串]上的答案。谢谢@EPB。使用json_decode()成功了。