我的数据库在带有特殊字符的JSON后面返回这个。我需要将其转换回原始字符:将编码的字符转换回原始字符 - PHP
{ "event_id":"5153",
"name":"Event Test",
"description":"Persönlichkeit Universität"",
"start_time":"2013-04-24 9:00 AM EST",
"end_time":"2013-04-24 5:00 PM EST"
}
我想删除所有的HTML字符。并将所有字符如ö
转换为原始字符。所以description
在上面的JSON实际上应该是这样的
PersönlichkeitUniversität大学”
我的阵列做array_walk
编码阵列JSON之前,和strip_tags
每个元素。 这是好的。(这导致上述JSON)
要获得字符回来,我想:
1. encoding again with utf8_encode
2. htmlspecialchars_decode
3. html_entity_decode //This one is eliminating the character altogether.
但没有给出原始字符。
任何想法?
更新:
我尝试这样做。但现在描述字段返回为空
array_walk_recursive($results, function (&$val) {
$val = strip_tags(html_entity_decode($val));
});
$results = json_encode($results);
怎么样在使用html_entity_decode之前json_encoding它呢? – bwoebi
在json_encode之前和之后,我看到了相同的结果。所以我不知道如何在json_encode帮助之前调用html_entity_decode? –