Closed erropix closed 4 years ago
have you tried loadHTMLFragment()
?
@goetas yes,
The issue is that it create a DOMDocumentFragment
instead of DOMDocument
, and I can't use DOMXpath query on it
is there a way to apply XPath::query
?
You can do this:
$doc = new DOMDocument();
$htm5 = new Html5([
'target_document' => $doc
]);
$frag = $htm5->loadHTMLFragment('html here...');
$doc->appendChild($frag);
$xpath = new DOMXpath($doc);
$el = $xpath->query('/div');
@ERROPiX Take a look at my library mundschenk-at/php-typography
for another workaround.
loadHTML()
force adding of doctype, HTML tag, and body tag when loading partial HTML stringIs there any way to do the same as