2016-11-25 190 views
0

我有一些奇怪的字符出现在生产数据库中。我想要替换的字符串是\ u00fc \ u00be \ u00a3 \ u00a4 \ u00bc。在php字符串中替换unicode字符的最佳方法是什么?

失败。

$column = str_replace('\u00fc\u00be\u008c\u00a3\u00a4\u00bc', "'", $column); 

和这个工程。

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

什么是最好的方法来取代PHP字符串中的unicode字符而不复制解码文本?

+0

这只是一个猜测,因为我无处可以测试这个atm,但在第一个例子中尝试使用双引号。单引号将其视为文字文本。 – Auris

+1

你应该看看http://stackoverflow.com/questions/6058394/unicode-character-in-php-string上的答案[编辑:该问题涉及单个字符,但同样的原则适用于他们的字符串。] – EPB

+0

谢谢@EPB。使用json_decode()工作。 –

回答

2

https://stackoverflow.com/users/395384/epb继铅之后,我用json_decode翻译其运作的Unicode。

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

使用""所以性格得到解析:

$column = str_replace("\u00fc\u00be\u008c\u00a3\u00a4\u00bc", "'", $column); 
+0

这没有奏效。 –

+0

语法为“\ u {00fc} \ u {00be} ...”([仅适用于PHP> = 7.0.0](http://php.net/manual/fr/migration70.new-features.php #migration70.new-features.unicode-码点转义语法)) – julp

相关问题