Reputation: 904
Background: We use handlebars templates. Small ones, which are needed only once, we inserted inside script, inside HTML. HTML are pre-translated, once on release.
Problem:
With simple_html_dom we find all relevant texts. Except those who are in the script tag!
Example "normal"
<h5 class="ues mt-1">Anmerkung ändern {bezeichnung}</h5>
Example inside script
<script id="template-Liste-Anmerkungen" type="text/x-handlebars-template">
<h5 class="ues mt-1">Anmerkung ändern {bezeichnung}</h5>
</script>
We find all relevant texts per class ues:
$html = new simple_html_dom();
$html->load($strHTML, true, false);
$HTMLElemente = $html->find('.ues');
All ues are found, no matter how deeply they are interlaced inside forms and modals. But the ues within the script tag are not found. It's always pure, clean HTML, what can we do?
Yes, I have found similar questions, some were not sufficiently documented, none had a relevant solution.
Upvotes: 0
Views: 702
Reputation: 54992
You want to iterate through the script tags and load the contents separately.
$str = <<<EOF
<script id="template-Liste-Anmerkungen" type="text/x-handlebars-template">
<h5 class="ues mt-1">Anmerkung ändern {bezeichnung}</h5>
</script>
EOF;
$doc = str_get_html($str);
foreach($doc->find('script') as $script){
$sub_doc = str_get_html($script->innertext);
foreach($sub_doc->find('.ues') as $el){
echo $el;
}
}
Upvotes: 1