【发布时间】:2011-03-22 07:52:30
【问题描述】:
PHP:: 简单的html dom parser(utf-8、windows-255等)如何获取网页的charset值?
备注:必须使用html dom parser http://simplehtmldom.sourceforge.net
Example1 网页字符集输入:
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
结果:utf-8
Example2 网页字符集输入:
<meta content="text/html; charset=windows-255" http-equiv="Content-Type">
结果:windows-255
编辑:
我试试这个(但它不起作用):
$html = file_get_html('http://www.google.com/');
$el=$html->find('meta[content]',0);
echo $el->charset;
应该改变什么? (我知道 $el->charset 不起作用)
谢谢
【问题讨论】:
-
对
//meta[@http-equiv="Content-Type"]/@content运行 xpath 查询。您必须自己解析属性值。 -
@Frank SimpleHTMLDom 不能做 Xpath
标签: php parsing html-parsing simple-html-dom php-parser