如何使用html简单dom获取Content-type?
我尝试 find('meta[http-equiv="Content-type"]')
但未能检索该信息。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我尝试 find('meta[http-equiv="Content-type"]')
但未能检索该信息。
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
SimpleHTMLDom 不在选择器中使用带引号的字符串文字。它只是
elem[attr=value]
。并且 value 的比较似乎区分大小写(可能有办法使其不区分大小写,但我不知道)*例如
打印
text/html;字符集=ISO-8859-1
。*编辑:是的,有一种方法可以执行不区分大小写的匹配,使用
*=
而不是=
edit2: btw that
http-equiv*=content -type
thingy 也会匹配(它只测试字符串是否位于属性值中的某个位置) 。但这是我能找到的唯一不区分大小写的函数/运算符。我想在这种情况下你可以接受它;-)
编辑3:它使用 preg_match('.../i') 并且模式/选择器直接传递给该函数。因此,您可以执行类似
http-equiv*=^content-type$
的操作来匹配http-equiv="Content-type"
但不能http-equiv="xyzContent-typeabc"
。但我不知道这是否是一个有保证的功能。SimpleHTMLDom doesn't use quoted string literals in the selector. It's just
elem[attr=value]
. And the comparison of value seems to be case-sensitive (there may be a way to make it case-insensitive, but that I don't know)*E.g.
prints
text/html; charset=ISO-8859-1
.*edit: yes, there is a way to perform a case-insensitive match, use
*=
instead of=
edit2: btw that
http-equiv*=content-type
thingy would also match<meta http-equiv="haha-no-content-types"...
(it only tests if the string is somewhere in the attribute's value). But it's the only case-insensitive function/operator I could find. I guess you can live with it in this case ;-)edit 3: It uses preg_match('.../i') and the pattern/selector is directly passed to that function. Therefore you could do something like
http-equiv*=^content-type$
to matchhttp-equiv="Content-type"
but nothttp-equiv="xyzContent-typeabc"
. But I don't know if this is a warranted feature.Content-Type 通常是 http 响应标头的一部分,而不是正文中。你从哪里得到xml文档?
The Content-Type is typically part of the http-response headers - not in the body. Where did you get the xml document from?
如果
content-type
的书写方式不同,我会在$this->find('meta');
上进行foreach
- 我认为在这种情况下,浏览器不区分大小写,而 php 可能会。I would go
foreach
on$this->find('meta');
in case of differently writtencontent-type
- I think that browsers aren't in this case case sensitive, while php might be.