-1

我有一个字符串:

"Hello\u00c2\u00a0World"

我想转换为:

"Hello World"

我尝试:

str_replace("\u00c2\u00a0"," ","Hello\u00c2\u00a0World");

或者

str_replace("\\u00c2\\u00a0"," ","Hello\u00c2\u00a0World");

但不行!

4

5 回答 5

1

解决!

str_replace(chr(194).chr(160)," ","Hello\u00c2\u00a0World");
于 2013-11-12T15:25:22.550 回答
0

你可以试试这个,取自这个答案

function replaceUnicode($str) {
    return preg_replace_callback("/\\\\u00([0-9a-f]{2})/", function($m){ return chr(hexdec($m[1])); }, $str);
}
echo replaceUnicode("Hello\u00c2\u00a0World");
于 2013-11-12T15:39:28.167 回答
0

这应该工作

$str="Hello\u00c2\u00a0World";   
echo str_replace("\u00c2\u00a0"," ",$str);
于 2013-11-12T15:00:46.037 回答
0

如果您想删除 \u.... 之类的模式,那么您可以使用它,例如:

$string = preg_replace('/(\\\u....)+/',' ',$input);
于 2013-11-12T14:58:35.577 回答
0

你是那里的大部分。

$stuff = "Hello\u00c2\u00a0World";
$newstuff = str_replace("\u00c2\u00a0"," ",$stuff);

您需要将 str_replace 的返回值放入一个变量中,以便稍后对其进行处理。

于 2013-11-12T15:00:13.247 回答