2014-11-22 98 views
0

我對我的產品的某些json解碼有問題,它們有特殊字符「æøå」。PHP json解碼與解決方案

解碼碼+呼應:

$products = json_decode($details['items'],true); 
foreach($products as $pro){ 
.. 
<?php echo $pro['name']; ?> 
.. 

在我的數據庫產品的名稱看起來是這樣的: '水療¥NER'。然而,在回聲中是:'Spu00e5ner'。它需要是'Spåner'。

我知道代碼沒有更新,但必須有一種方法來顯示特殊字符。

+0

這看起來像Unicode字符未被正確處理的問題(U + 00e5解碼爲一個)。在[這個SO問題](http://stackoverflow.com/questions/3650754/unicode-string-php)的答案可以有幫助嗎? – 2014-11-22 13:48:38

+0

這沒有幫助:/ – 2014-11-22 13:55:53

+0

http://stackoverflow.com/questions/279170/utf-8-all-the-way-through – georg 2014-11-22 14:12:34

回答

0

我做了一個功能,可以幫助你解決你的問題。

function convertChars($char){ 

$return = html_entity_decode(htmlentities($char, ENT_QUOTES, 'UTF-8'), ENT_QUOTES , 'ISO-8859-15'); 
$return = iconv("UTF-8","ASCII//TRANSLIT",$return); 
return strtolower(preg_replace('/[^a-zA-Z0-9]+/','',$return)); 

}