DOMDocument
とを使用するのはどうDOMDocumentType
ですか。
$xml = new DOMDocument();
$xml->loadHTMLFile($url);
$name = $xml->doctype->publicId; // -//W3C//DTD XHTML 1.0 Strict//EN
$doctype
次の値が含まれるようになりました。
DOMDocumentType Object
(
[name] => html
[entities] => (object value omitted)
[notations] => (object value omitted)
[publicId] => -//W3C//DTD XHTML 1.0 Strict//EN
[systemId] => http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd
[internalSubset] =>
[nodeName] => html
[nodeValue] =>
[nodeType] => 10
[parentNode] => (object value omitted)
[childNodes] =>
[firstChild] =>
[lastChild] =>
[previousSibling] =>
[nextSibling] => (object value omitted)
[attributes] =>
[ownerDocument] => (object value omitted)
[namespaceURI] =>
[prefix] =>
[localName] =>
[baseURI] =>
[textContent] =>
)
したがって、タイプを簡単に抽出できるようになりました。
$name = $xml->doctype->publicId;
$name = preg_replace('~.*//DTD(.*?)//.*~', '$1', $name);
echo $name;
結果は になりXHTML 1.0 Strict
ます。ここでのphpfiddleの例。