它应该是$element->attr
foreach ( $html->find('meta') as $element ) {
var_dump($element->attr);
}
输出
array
'http-equiv' => string 'refresh' (length=7)
'content' => string '100' (length=3)
array
'http-equiv' => string 'Content-Type' (length=12)
'content' => string 'text/html; charset=utf-8' (length=24)
array
'name' => string 'robots' (length=6)
'content' => string 'noindex' (length=7)
简单检查
foreach ( $html->find('meta') as $element ) {
foreach ( $element->attr as $key => $value ) {
if ($key == "http-equiv" && $value == 'refresh') {
echo "FOUND";
}
}
}
输出
FOUND
笔记*
如果你$element->attr["http-equiv"]
直接使用它会产生下面的错误,因为网站有时没有http-equiv
注意:未定义索引:http-equiv