working on fragments?
CanRau opened this issue · comments
Can Rau commented
is it working on html fragments, too? can't get it working
my html <p>paragraph</p><p>paragraph2</p>
and my php
$dom = new \IvoPetkov\HTML5DOMDocument();
$dom->loadHTML($content);
$paragraphs = $dom->getElementsByTagName('p');
var_dump($paragraphs);
the backslash because my php got another namespace..
Ivo Petkov commented
The fragments are automatically inserted into a body element, so they work fine. I tested your code on my machine (PHP 7.1 with libxml v2.9.4), and it works great. Can you please share your environment.
Can Rau commented
got it working now, don't know what happened yesterday..what is the proper/best way to strip the added doctype and body to get the initial fragment? str_replace or are there any other options?
Ivo Petkov commented
I'd recommend:
$content = $dom->querySelector('body')->innerHTML;
Can Rau commented
Thanks and sorry for not responding..I had to hold this work for now..