I write a script:

$ff = '«'; echo $ff.'<br>'; echo json_encode(array('data'=>$ff)); //Вывод: //« //{"data":"\u00ab"} 

I am writing the second:

 $ff = html_entity_decode('&laquo;'); echo $ff.'<br>'; echo json_encode(array('data'=>$ff)); //Вывод: //« //{"data":null} 

Instead of html_entity_decode('&laquo;') you can write chr(171) . The result is the same, wtf? How to explain?

PS System in utf-8

  • I have other results, this was confirmed on IDEone: ideone.com/ZgYip3 Try explicitly setting the default encoding: ini_set ('default_charset', 'UTF-8'); - ReinRaus
  • Did not help. Shitty ... - co11ter
  • Yes. I have the same results on localhost. - ReinRaus
  • one
    So: setlocale (LC_ALL, "en_US.UTF-8"); or so (preferably): html_entity_decode ('& laquo;', null, "UTF-8") - ReinRaus
  • I suppose that in ideone, the data on the server goes to the already encoded (did not check). Now I will try other options - co11ter

1 answer 1

Try this:

 html_entity_decode('&laquo;', null, "UTF-8") 
  • I read the description of the php.net function : html_entity_decode and it turned out that:> Encoding for use. If not specified, the default value for this argument is ISO-8859-1 in PHP versions up to 5.4.0 and UTF-8 starting with PHP 5.4.0 and further I have php 5.5.4, you probably have a lower version. In order for this function to take the encoding from the php settings, you need to pass an empty string to it: html_entity_decode ('& laquo;', null, ""); Therefore, the default encoding manipulations were not obtained. - ReinRaus
  • Exactly !! php 5.3.10. Thanks for the help) - co11ter