The unicode code point for the Chinese word 你好 is 4F60 , 597D respectively. which I got from this tool http://rishida.net/tools/conversion/
The console application below will print out the hexadecimal byte sequence of 你好 as 60:4F:7D:59 . As you can see it's in reverse order of the unicode code point for each character. 60 first then 4F, instead of 4F then 60. Why is it so ? Who is correct ? The tools or the console app ? Or both ?
void printHex (char * buf, char *filename)
{
FILE *fp;
fp=fopen(filename, "w");
if(fp == NULL) return;
int len2 = sizeof(buf);
int i;
char store[10];
for (i = 0; i < sizeof(buf); i++)
{
if (i > 0) fprintf(fp,":");
//sprintf(store, );
fprintf(fp,"%02X", buf[i]);
}
fprintf(fp,"\n");
fclose(fp);
}
int main(int argc, char* argv[])
{
char * str3 = (char*)(L"你好");
printHex( str3, "C:\\Users\\william\\Desktop\\My Document\\test2.txt");
return 0;
}
While in PHP when I use this mb_convert_encoding function.
echo bin2hex(mb_convert_encoding("你好", "UTF-16", "UTF-8")); //result : 4f60 597d
echo bin2hex(mb_convert_encoding("恏絙", "UTF-16", "UTF-8")); //result : 604f 7d59
The PHP has the result same as the online tool, but when I use this encoding to print 你好 on a printer using php_printer.dll functions, the print out become 恏絙 and vice versa. But the C++ application can print out correctly. What could be wrong with PHP ? And the solution?