用php中的实际数据替换unicode

时间:2015-10-07 10:31:34

标签: php html unicode

我想替换 unicode \ u00a0 php 中的实际数据。

示例:NSDictionary *environment = [[NSProcessInfo processInfo] environment];

1 个答案:

答案 0 :(得分:1)

\u00a0NO-BREAK SPACE

escape sequence

要解码escape sequence中的任何 PHP,您可以使用此功能:

function unicodeString($str, $encoding=null) {
    if (is_null($encoding)) $encoding = ini_get('mbstring.internal_encoding');
    return preg_replace_callback('/\\\\u([0-9a-fA-F]{4})/u', create_function('$match', 'return mb_convert_encoding(pack("H*", $match[1]), '.var_export($encoding, true).', "UTF-16BE");'), $str);
}
echo unicodeString($str);
//<b>Sort By - </b><a href="http://pagalworld.com/files/9704/Dil Dhadakne Do (2015) Mp3 Songs/atoz/1.html">A to Z | </a><a href="http://pagalworld.com/files/9704/Dil Dhadakne Do (2015) Mp3 Songs/recent/1.html">Recently Added | </a><a href="http://pagalworld.com/files/9704/Dil Dhadakne Do (2015) Mp3 Songs/downloads/1.html">Most Downloaded</a>

样本:

https://ideone.com/9QtzMO

如果您只需要替换 escape sequence,请使用:

$str = str_replace("\u00a0", " ", $str);
echo $str;
<b>Sort By - </b><a href="http://pagalworld.com/files/9704/Dil Dhadakne Do (2015) Mp3 Songs/atoz/1.html">A to Z | </a><a href="http://pagalworld.com/files/9704/Dil Dhadakne Do (2015) Mp3 Songs/recent/1.html">Recently Added | </a><a href="http://pagalworld.com/files/9704/Dil Dhadakne Do (2015) Mp3 Songs/downloads/1.html">Most Downloaded</a>