开发者

Php DomDocument not finding element by Id

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜