yosra Posted April 23, 2013 Share Posted April 23, 2013 i want to convert a string to two-byte UNICODE (UCS-2) i have been tryin this command $str =mb_convert_encoding($str,"UCS2","UTF-8"); but it doesn't work the string won't convert Quote Link to comment Share on other sites More sharing options...
jugesh Posted April 23, 2013 Share Posted April 23, 2013 Check on the link given below: http://php.net/manual/en/ref.mbstring.php Quote Link to comment Share on other sites More sharing options...
requinix Posted April 23, 2013 Share Posted April 23, 2013 This page may be more useful. Spoiler alert: it's not "UCS2". Quote Link to comment Share on other sites More sharing options...
yosra Posted April 23, 2013 Author Share Posted April 23, 2013 ohhh yes i change it UCS-2 samething it didn't work Quote Link to comment Share on other sites More sharing options...
kathas Posted April 23, 2013 Share Posted April 23, 2013 Chances are the input string is not utf-8. I would suggest the following print_r( mb_list_encodings() ); and check if ucs-2 is in the list. If it is then probably the input string is not utf-8. Quote Link to comment Share on other sites More sharing options...
yosra Posted April 23, 2013 Author Share Posted April 23, 2013 yes UCS-2 does exist [16] => UCS-2 Quote Link to comment Share on other sites More sharing options...
requinix Posted April 23, 2013 Share Posted April 23, 2013 (edited) What does echo mb_detect_encoding($str, "UTF-8,ASCII"); output? (Before you try this conversion.) Edited April 23, 2013 by requinix Quote Link to comment Share on other sites More sharing options...
yosra Posted April 23, 2013 Author Share Posted April 23, 2013 it's UTF-8 Quote Link to comment Share on other sites More sharing options...
requinix Posted April 24, 2013 Share Posted April 24, 2013 What is an example string (preferably one with unusual characters) and the bin2hex($str) of it? Quote Link to comment Share on other sites More sharing options...
yosra Posted April 24, 2013 Author Share Posted April 24, 2013 i tried bin2hex("admin") =>61646d696e bin2hex("^à@kol")=>5ec3a0406b6f6c Quote Link to comment Share on other sites More sharing options...
kathas Posted April 25, 2013 Share Posted April 25, 2013 You could also tell us the output of the conversion. bin2hex(mb_convert_encoding("^à@kol","ucs-2","utf-8")) // 005e00e00040006b006f006c which is correct ucs-2 big endian. Quote Link to comment Share on other sites More sharing options...
yosra Posted April 25, 2013 Author Share Posted April 25, 2013 yes bin2hex(mb_convert_encoding("^à@kol","ucs-2","utf-8")) gives me the same output thank u Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.