Single first-level element is stripped
Thanty opened this issue · 6 comments
What is this feature about (expected vs actual behaviour)?
If string contains only one parent element, parser strips this one from the result.
$d = new voku\helper\HtmlDomParser;
$d->loadHtml("<p>p1</p><p>p2</p>");
echo (string)$d; // <p>p1</p><p>p2</p> - correct
$d->loadHtml("<div><p>p1</p></div>");
echo (string)$d; // <p>p1</p> - incorrect
I don't know if this is an expected behavior, but seems broken for me... Right now I have to manually wrap initial html in a div element and if it contains several root elements this div stays in generated html.
Issue Label Bot is not confident enough to auto-label this issue. See dashboard for more details.
I created a test for PHP 7.0 - 7.4 and can't see this problem: https://travis-ci.org/voku/simple_html_dom/builds/631294151 ? Do you use Windows or Linux?
Hi! Sorry for the waiting...
I'm also sorry for this case. Problem occurs only when using save()
method.
My guess is in original class "root" element was created automatically (maybe <html>
or so) and the final result was generated from "root" innerHtml. https://github.com/samacs/simple_html_dom/blob/master/simple_html_dom.php#L1145
I don't know if a html wrapper or the full html is better [more expected]? What do you think of this: 284fe40
As for me, html()
is more expected and it is the original behaviour.
Method save()
is supposed to be used for saving the result to a file, so...
Fixed in version 4.7.11