I have a strings like
$string1 = 'love is all mine 🔥';
$string2 = '🔥Sarah is good girl⭐';
$string3 = 'हिन्दी ya ⭐';
$string4 = 'hái 还/還 ("still"), yǐjīng 已经 ';
i want to encode them in a harmless encoded strings like
Api Hatal\u0131d\u0131r. L\u00fctfen kontrol ederek tekrar deneyiniz
in which no special charactor and utf8 character so that i can use it in javascript. I have tried utf8_encode() and mb_convert_encoding( $string4 , 'UTF-8', 'UCS-2BE');. utf8_encode() is simply not working as it is giving error in javasciprt (because i want to create json response and to use it in my code). and mb_convert_encoding( $string4 , 'UTF-8', 'UCS-2BE'); is converting whole string into other Chinese characters.
-
1i tried "json_encode(string)" and it just worked.Amir Hedieh– Amir Hedieh2018年12月01日 11:48:28 +00:00Commented Dec 1, 2018 at 11:48
-
Your code is also valid JavaScript.Tom Blodget– Tom Blodget2018年12月04日 16:50:22 +00:00Commented Dec 4, 2018 at 16:50
1 Answer 1
you can use iconv for converting
iconv('utf-8', 'utf-8//IGNORE',$str);
and change utf-8 encoding to anything you want. first parameter is your current text encoding and second one is which encoding you want to convert it to.function doc is ...
string iconv ( string $input_charset, string $output_charset, string $str )
1 Comment
\u0131d\u0131 ?