0
$sampleText = "Episode 8 - Dansk dokumentarserie. Jørgen og John drar ut for å";

I need to convert it to json and encode it in a way to make it AJAX safe.

I tried following encoding :

//$name = htmlentities(utf8_encode($sampleText), ENT_QUOTES);
//$name = htmlentities($sampleText, ENT_COMPAT, 'UTF-8');
//$name = htmlentities(utf8_encode($sampleText), ENT_COMPAT);

Sometimes it works but in some cases I get \. which makes json invalid.

Example : Gäster är kulturminster Alice \. Bah Kuhnke och komikern William Spetz.Kategori: TalkShow \..

Invalid JSON due to string \. :

[{"name" : "Humortalkshow."}, 
 {"name" : "Temat 2013 var \."}, 
 {"name" : "Talkshow \."}]

Could you please help me encode the foreign characters in a proper way.

Kunwarbir S.
  • 281
  • 1
  • 3
  • 13

0 Answers0