@ 2018-10-30T01:51:17Z <?php
$html = <<<HTML
<div class="intro">
<div class="desc-wrap">
Text Text Text
</div>
<div class="main-wrap">
<table class="table-wrap">
<tbody>
<tr>
<th class="range">Range </th>
<th>#1</th>
<th>#2</th>
</tr>
</tbody>
</table>
</div>
</div>
<div class="intro">
<div class="desc-wrap">
Text Text Text
</div>
<div class="main-wrap">
<table class="table-wrap">
<tbody>
<tr>
<th class="range">Range </th>
<th>#1</th>
<th>#2</th>
<th>#3</th>
<th>#4</th>
</tr>
</tbody>
</table>
</div>
</div>
<div class="intro">
<div class="desc-wrap">
Text Text Text
</div>
<div class="main-wrap">
<table class="table-wrap">
<tbody>
<tr>
<th class="range">Range </th>
<th>#1</th>
</tr>
</tbody>
</table>
</div>
</div>
<div class="intro">
<div class="desc-wrap">
Text Text Text
</div>
<div class="main-wrap">
<table class="table-wrap">
<tbody>
<tr>
<th class="range">Range </th>
<th>#1</th>
<th>#2</th>
<th>#3</th>
<th>#4</th>
<th>#5</th>
</tr>
</tbody>
</table>
</div>
</div>
HTML;
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($html);
$xp = new DOMXPath($dom);
foreach ($xp->query("//div[contains(@class,'main-wrap')]/table[contains(@class, 'table-wrap')]//tr") as $node) {
//echo $node->childNodes->length , "\n";
echo $xp->query("th", $node)->length , "\n";
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 5.6.0 - 5.6.40 , 7.0.0 - 7.0.33 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.19 , 8.3.0 - 8.3.4 , 8.3.6 - 8.3.7 3
5
2
6
Output for 8.3.5 Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
3
5
2
6
preferences:dark mode live preview
143.87 ms | 402 KiB | 289 Q