Any one can help me ? how could I get UCS2/HexEncoded characters
like 'Hello' will return "00480065006C006C006F"
This are the HexEncoded values:
0048 = H 0065 = e 006C = l 006C = l 006F = o*
Also in arabic (!مرحبا عالم) will return 06450631062d0628064b06270020063906270644064500200021
How I can get the encoded UCS2 in php?
mb_convert_encoding($str, 'UCS-2', 'auto') works correctly to convert the string, but you'll have to do extra work to get the proper output in a browser.
You'll need to change the character set of your output to match UCS-2 in order to be able to use echo to output it to a page. Also, you may need to set the Content-Type via a meta tag in the header as well.
I've included three examples here in the following unicode variants: UCS-2, UTF-16, and UTF-8; as not all of them worked for me without tweaking in Internet Explorer. You may need to store your PHP files in UTF-8 to get proper results. Also, I am on an english version of Windows, so I can't enter your arabic string in proper RTL form. I'm sorry if your string is garbled here. I assure you that if you replace it in the location noted by my comments, you'll get the proper result. Finally, you may have trouble viewing UCS-2 and UTF-16 in internet explorer- there seems to be some oddities when the output is reloaded via a cache. However, FireFox 3.5.5 worked for all three encodings. If you're serious about making an app, I strongly recommend you consider using UTF-8 instead of UCS-2.
UCS-2 Version
FireFox 3.5.5 (Ok, but FireFox says it is UTF-16BE on my test.)
Internet Explorer 7.0 (Not Ok. Didn't detect/convert Arabic properly.)
UTF-16 Version
FireFox 3.5.5 (100% Ok)
Internet Explorer 7.0 (Fail. May have to specify Byte-Order.)
UTF-8
FireFox 3.5.5 (100% Ok)
Internet Explorer 7.0 (100% Ok)