PHP::如何简单地获取网页的字符集值html dom 解析器 http://simplehtmldom.sourceforge.net/(utf-8、windows-255 等)?
备注:必须使用 html dom 解析器来完成http://simplehtmldom.sourceforge.net http://simplehtmldom.sourceforge.net
示例1 网页字符集输入:
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
结果:utf-8
示例2 网页字符集输入:
<meta content="text/html; charset=windows-255" http-equiv="Content-Type">
结果:windows-255
Edit:
我尝试这个(但它不起作用):
$html = file_get_html('http://www.google.com/');
$el=$html->find('meta[content]',0);
echo $el->charset;
应该改变什么?
(我知道 $el->charset 不起作用)
Thanks
您必须使用正则表达式来匹配字符串(我希望您有 PCRE...)。
$el=$html->find('meta[http-equiv=Content-Type]',0)
$fullvalue = $el->content;
preg_match('/charset=(.+)/', $fullvalue, $matches);
echo $matches[1];
不是很健壮,但应该可以工作。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)