获取带有汉字PHP的源代码 [英] Get source code with Chinese characters PHP

查看:220
本文介绍了获取带有汉字PHP的源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我放弃了。
我一直在搞乱所有我想到的从目标网站检索数据,其中包含繁体中文编码信息(charset = GB2312)。



我一直使用simple_html_parser像往常一样,但它似乎没有返回汉字,实际上我得到的是一些奇怪的问号嵌入菱形形状内。
( ѯ ؼ ֣ 像这样)



声明php文件的编码没有



通过声明我是指:

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

我无法获得任何以中文书写的数据,也尝试过 file_get_contents 与同样的运气。



提前感谢。

nofollow noreferrer> mb_convert_encoding 或 iconv ,例如

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

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


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);

这篇关于获取带有汉字PHP的源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆