0

I have a problem with some json decode of my products, which have special characters "æøå".

Decode code + echo:

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

In my database the name of the product looks like this: 'SpÃ¥ner'. However, in the echo it's: 'Spu00e5ner'. It need to be 'Spåner'.

I know the code isn't updated, but there gotta be a way to show the special characters.

  • This looks like an issue with unicode characters not being properly handled (U+00e5 decodes to å). Could the answers in [this SO question](http://stackoverflow.com/questions/3650754/unicode-string-php) be helpful? – Roger Filmyer Nov 22 '14 at 13:48
  • http://stackoverflow.com/questions/279170/utf-8-all-the-way-through – georg Nov 22 '14 at 14:12

1 Answers1

0

I made a function that might help you with your problem.

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));

}

alphawow
  • 390
  • 2
  • 7