Encoding problems
$url ="http://www.amazon.co.jp/dp/B007HDJPOU"; $handle=mb_convert_encoding(file_get_contents($url), 'UTF-8','utf-8, shft-jis, gbk');$sumopen=fopen("001.txt","w");fwrite($sumopen,$handle);fclose($sumopen);
This code saves the code to the txt file. now the Japanese part is full of garbled characters. how can this problem be solved?
?????? Why? /Span>
???????? /Span>
???????????
Reply to discussion (solution)
Shift-jis encoding, no conversion
He has
Mb_convert_encoding (file_get_contents ($ url), 'utf-8', 'utf-8, shft-jis, gbk ');
Is it wrong?
Only the page code can be changed to Shift_JIS ??
What did you write?
'Utf-8', 'utf-8, shft-jis, gbk'
Xuzuning has been changed.
The output file is garbled.
$handle=mb_convert_encoding(file_get_contents($url), 'UTF-8','utf-8, shft_jis, gbk');$sumopen=fopen("001.txt","w");fwrite($sumopen,$handle);fclose($sumopen);
Another question is: why does the source code I obtain differ from that in the browser?
$ Handle = mb_convert_encoding (file_get_contents ($ url), 'utf-8', 'utf-8, shift_jis, gbk ');
After thinking about it, I feel that the encoding has been converted.
The problem should be caused by writing files. change it to this.
$ Sumopen = fopen ("001.txt"," w B ");
It is output by byte. if you open this txt file, you must choose to open it without bom UTF-8.