我的數據庫在帶有特殊字符的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? –