“描述”的文本格式化数组变量在图协议中 [英] text formattation of "description" array variable in graph protocol
问题描述
在我正在开发的网站上,我正在使用一个功能来获取Facebook上从群组中获取的事件的信息。
我注意到,使用图形协议,创建的数组的描述中包含的文本,对于新行,有像\ u00b或\ n这样的奇怪字符。
如何显示格式正确的内容?
提前感谢
Piero
On the website I am developing, I'm using a function that get information about events taken from a group on facebook. I noticed that using the graph protocol, the text contained in the "description" of the created array , there are strange characters like "\ u00b" or "\ n" for new lines. How can I do to display the content formatted correctly? thanks in advance Piero
推荐答案
它被称为 unicode_decode
( http://webarto.com/83/php-unicode_decode-5.3),它将在PHP6之后出现...
It is called unicode_decode
( http://webarto.com/83/php-unicode_decode-5.3 ), it will come out in PHP6 until then...
function unicode_decode($string) {
$string = preg_replace_callback('#\\\\u([0-9a-f]{4})#ism',
create_function('$matches', 'return mb_convert_encoding(pack("H*", $matches[1]), "UTF-8", "UCS-2BE");'),
$string);
return $string;
}
Raska Top\\\čagi \\\ć
RaskaTopčagić
Raska Top\u010dagi\u0107 Raska Topčagić
如果你不使用PHP,抱歉...
If you are not using PHP, sorry...
更好的解决方案:
echo json_decode('Raska Top\u010dagi\u0107'); # Raska Topčagić
这篇关于“描述”的文本格式化数组变量在图协议中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!