我正在使用PHP DOMNode hasAttributes检索所有元素的属性。到目前为止,一切都很好。我的代码如下。但是,这条线else if($imageTags->hasAttributes() == false) is where I can't get it to work
,它显示错误在我的页面上,而不是重定向用户索引PHP时,代码无法正常工作。我真正想要的是如果($imageTags->hasAttributes() == true)
不等于TRUE。将用户重定向到index.php,而不是显示错误。PHP DOMNode :: hasAttributes检查失败
function get_iframe_attr($string){
$doc = new DOMDocument();
$doc->loadHTML("$string");
$imageTags = $doc->getElementsByTagName('iframe')->item(0);
if ($imageTags->hasAttributes() == true) {
foreach ($imageTags->attributes as $attr) {
$name = $attr->nodeName;
$value = $attr->nodeValue;
$attr_val[] = "$name=\"$value\" ";
}
echo $implode_str = implode(" ", $attr_val);
}else if($imageTags->hasAttributes() == false){
header("Location: index.php");
}
}
get_iframe_attr('<iframe src="" scrolling="no" width="600" height="438" marginheight="0" marginwidth="0" frameborder="0"></iframe>');
注意:如果您删除字符串上的'<iframe'
标记。你会得到错误
'如果你删除字符串上的'
我试图理解你的意思,“如果你删除字符串上的”
是的!这其实就是我想要做的。 – user2310422 2013-04-26 03:45:31