2

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.

2
  • 1
    i tried "json_encode(string)" and it just worked. Commented Dec 1, 2018 at 11:48
  • Your code is also valid JavaScript. Commented Dec 4, 2018 at 16:50

1 Answer 1

2

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 )
Sign up to request clarification or add additional context in comments.

1 Comment

will it make utf8 charactors as \u0131d\u0131 ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.