You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What is this feature about (expected vs actual behaviour)?
When parsing a file, I would like to have the original html of an element, so that I can search-replace a specific part of a document, without changing/updating the rest.
The issue is that $el->html does not return the right string, if any of its childs has more than one child. It introduces additional linebreaks.
How can I reproduce it?
Script: (it shows my full use-case; the notable part is highlighted)
<?phpusevoku\helper\HtmlDomParser;
require_once'../composer/autoload.php';
$fileContent = file_get_contents('./test.html');
$dom = HtmlDomParser::str_get_html($fileContent);
foreach($dom->find('.mydiv') as$myDivEl) {
$currentHtml = $myDivEl->html;
echo$currentHtml; // <---- here you can see the wrong output (you can skip the rest)$newContent = "";
foreach($myDivEl->find('.mydiv-item') as$childEl) {
$childEl->class = 'replaced';
$newContent .= $childEl;
}
$myDivEl->outerhtml = '<div class="myreplacement">' . $newContent . '</div>';
$fileContent = str_replace($currentHtml, $myDivEl->html, $fileContent);
}
file_put_contents('./test-out.html', $fileContent);
The issue is, that the html of the selected elements is not the same, if an element has more than one child. Therefore the search-replace does not work correctly:
It would also help me, if I can get the original parsed text, so that I can (search &) replace it. Maybe indices (from-to) of the original parsed string.
What is this feature about (expected vs actual behaviour)?
When parsing a file, I would like to have the original html of an element, so that I can search-replace a specific part of a document, without changing/updating the rest.
The issue is that
$el->html
does not return the right string, if any of its childs has more than one child. It introduces additional linebreaks.How can I reproduce it?
Script: (it shows my full use-case; the notable part is highlighted)
Input HTML file:
Actual output: (B is not replaced)
Expected output:
The issue is, that the html of the selected elements is not the same, if an element has more than one child. Therefore the search-replace does not work correctly:
B should be:
Does it take minutes, hours or days to fix?
Minutes?
Any additional information?
.
Thanks for your help!
The text was updated successfully, but these errors were encountered: