开发者

Php DomDocument not finding element by Id

开发者 https://www.devze.com 2023-02-14 20:11 出处:网络
I have written the following php: $html = \"<div id=\'title\'>someTitle</div>\"; $docToAdd = new DomDocument();

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号