PHP DomDocument返回Doctype
我以为这会比以前容易,或者我想得太多了 我试图从url返回html页面声明的doctype。 如果不是别的!DOCTYPE html将其附加为!DOCTYPE html 我尝试了几种不同的方法…最新的是下面的数组返回,但是不管测试的页面是什么,返回的数组都是完全相同的,即使完全声明的DOCTYPE不相同 任何关于我做错了什么或如何解决这个问题的想法都将不胜感激PHP DomDocument返回Doctype,php,Php,我以为这会比以前容易,或者我想得太多了 我试图从url返回html页面声明的doctype。 如果不是别的!DOCTYPE html将其附加为!DOCTYPE html 我尝试了几种不同的方法…最新的是下面的数组返回,但是不管测试的页面是什么,返回的数组都是完全相同的,即使完全声明的DOCTYPE不相同 任何关于我做错了什么或如何解决这个问题的想法都将不胜感激 <!DOCTYPE html> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1
<!DOCTYPE html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
$url="http://www.example.com";
$html = file_get_contents($url);
$doc = new DOMDocument();
$doc->loadHTML(htmlentities($html));
$doctype = $doc->doctype;
var_dump($doctype);
您不需要调用htmlentities:
$html='';
$doc=新的DOMDocument();
$doc->loadHTML($html);
$doctype=$doc->doctype;
变量转储($doctype);
谢谢你……回顾一下我尝试过的其他10件事……除了var_dump之外,我有你的确切代码……我正在尝试回显它。
object(DOMDocumentType)#2 (22) {
["name"]=> string(4) "html"
["entities"]=> string(22) "(object value omitted)"
["notations"]=> string(22) "(object value omitted)"
["publicId"]=> string(37) "-//W3C//DTD HTML 4.0 Transitional//EN"
["systemId"]=> string(41) "http://www.w3.org/TR/REC-html40/loose.dtd"
["internalSubset"]=> NULL
["nodeName"]=> string(4) "html"
["nodeValue"]=> NULL
["nodeType"]=> int(10)
["parentNode"]=> string(22) "(object value omitted)"
["childNodes"]=> NULL
["firstChild"]=> NULL
["lastChild"]=> NULL
["previousSibling"]=> NULL
["nextSibling"]=> string(22) "(object value omitted)"
["attributes"]=> NULL
["ownerDocument"]=> string(22) "(object value omitted)"
["namespaceURI"]=> NULL
["prefix"]=> string(0) ""
["localName"]=> NULL
["baseURI"]=> NULL
["textContent"]=> string(0) "" }