I have written the following php:
$html = "<div id='title'>someTitle</div>";
$docToAdd = new DomDocument();
$docToAdd->validateOnParse = true;
$docToAdd->loadHTML($html);
if($docToAdd->getElementById('title') == null){
echo "null";
}
else{
开发者_运维知识库 echo $docToAdd->getElementById('title')->tagName;
}
Why does it echo null
when I clearly have just added am element with id 'title'
?
Thanks
If the HTML does not contain a doctype declaration, getElementById
will always return null
.
精彩评论