开发者

Get source code with Chinese characters PHP

开发者 https://www.devze.com 2022-12-20 10:08 出处:网络
Well, I give up. I\'ve been messing around with all I could think of to retrieve data from a target website that has information in traditional Chinese encoding (charset=GB2312).

Well, I give up. I've been messing around with all I could think of to retrieve data from a target website that has information in traditional Chinese encoding (charset=GB2312).

I've been using the simple_html_parser like always but it doesn't seem to return the Chinese characters, in fact all I get are some weird question marks embedded inside a rhomboid shape. ("�������ѯ�ؼ��֣�" Like so)

Declaring the encoding for the php file didn't do anything except of getting rid of some unwanted character showing at the start of the page.

By declaring it I mean:

header('Content-Type', 'text/html; charset=GB2312');

I can't get any data that's written in Chinese, also tried file_get_contents with the same luck. I'm probably missing something obvious since I can't find开发者_运维百科 any related discussion elsewhere.

Thanks in advance.


Have you tried converting the encoding with mb_convert_encoding or iconv, e.g.

$str = mb_convert_encoding($content, 'UTF-8', 'GB2312');

or

$str = iconv("UTF-8", "GB2312//IGNORE", $content);


Get it in whatever character set the source uses, then convert it to something usable locally, such as UTF-8. Then send it to the browser.


set header('Content-Type: text/html; charset=utf-8');

It's working for me

0

精彩评论

暂无评论...
验证码 换一张
取 消