Matcher
Matcher copied to clipboard
how to print innerHTML?
when you match some element/div, and you print it, it trimms all the
s and and other tags between tag. Like for example:
<div class="tag">
<div class="second">Example text <br> another text <a href="#">h1</a> end of text. </div>
<div class="second">Example text <br> second row <a href="#">h2</a> end of text. </div>
</div>
how would you loop second div classes, and have as a result full innerHtml() with all html tags and not just "Example text another text end of text."
Thanks for great library...
There's no direct support for this in the Matcher but it can be easily done. There's multiple ways to do it, one of them is to use the mapRaw
method which apply a function to raw DOM nodes produced by Matcher. But a simpler method might be to chain a function inside the multi
matcher
$m = Matcher::multi('//div[@class="second"]', function ($n) {
$html = '';
foreach ($n->childNodes as $ch) {
$html .= $n->ownerDocument->saveHTML($ch);
}
return $html;
})->fromHTML();