Encoding-php Tutorial

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.