PHP converts unicode to hex

The application wants me to insert strings as text encoded using hex values in proper coding. , and the encoding is Unicode_No_Compression

For example, for Sześć siedem correct line is HEX 0053007A0065015B0107002000730069006500640065006D ,
Źdźbło = 01790064017A00620142006F
String with no special chars = 0053007400720069006E0067002000770069007400680020006E006F0020007300700065006300690061006C002000630068006100720073

I tried playing with MySQL HEX() / UNHEX() and dechex() PHP, but could not figure out how to do this conversion. Any ideas?

+4
source share
2 answers

Basically you are looking at the hexadecimal version of the UCS-2 encoding, I guess. Therefore:

 php > echo strtoupper(bin2hex(iconv('UTF-8', 'UCS-2', 'Źdźbło'))); 01790064017A00620142006F 
+8
source

Try the following:

 $out = implode("",array_map(function($x) {return sprintf("%04X",ord($x));},str_split($in))); 

One insert;)

0
source

All Articles