3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <table cellspacing="1" cellpadding="1" class="troop_details inAttack" > <thead> <tr> <td class="role"> <a href="/karte.php?d=91629">02]</a> </td> <td colspan="11" class="troopHeadline"> <a class="markAttack" onclick="Travian.AttackSymbol.markAttackSymbol(29447487);return false;"><img id="markSymbol_29447487" class="markAttack markAttack0" src="/img/x.gif" title="mark attack" alt="mark attack" /></a> <a href="/karte.php?d=91628">Uanm attacks 01] #WorkInProgress</a> </td> </tr> </thead> <tbody class="units"> <tr> <th class="coords"> &#x202d;<span class="coordinates coordinatesWrapper coordinatesAligned coordinatesltr"><span class="coordinateX">(&#x202d;0&#x202c;</span><span class="coordinatePipe">|</span><span class="coordinateY">&#x202d;&minus;&#x202d;28&#x202c;&#x202c;)</span></span>&#x202c; </th> <td class="uniticon"> <img class="unit u21" title="Phalanx: 0:04:17" alt="Phalanx" src="/img/x.gif" /> </td> <td class="uniticon"> <img class="unit u22" title="Swordsman: 0:05:00" alt="Swordsman" src="/img/x.gif" /> </td> <td class="uniticon"> <img class="unit u23" title="Pathfinder: 0:01:46" alt="Pathfinder" src="/img/x.gif" /> </td> <td class="uniticon"> <img class="unit u24" title="Theutates Thunder: 0:01:35" alt="Theutates Thunder" src="/img/x.gif" /> </td> <td class="uniticon"> <img class="unit u25" title="Druidrider: 0:01:53" alt="Druidrider" src="/img/x.gif" /> </td> <td class="uniticon"> <img class="unit u26" title="Haeduan: 0:02:18" alt="Haeduan" src="/img/x.gif" /> </td> <td class="uniticon"> <img class="unit u27" title="Ram: 0:07:30" alt="Ram" src="/img/x.gif" /> </td> <td class="uniticon"> <img class="unit u28" title="Trebuchet: 0:10:00" alt="Trebuchet" src="/img/x.gif" /> </td> <td class="uniticon"> <img class="unit u29" title="Chieftain: 0:06:00" alt="Chieftain" src="/img/x.gif" /> </td> <td class="uniticon"> <img class="unit u30" title="Settler: 0:06:00" alt="Settler" src="/img/x.gif" /> </td> <td class="uniticon last"> <img class="unit uhero" title="Hero" alt="Hero" src="/img/x.gif" /> </td> </tr> </tbody> <tbody class="units last"> <tr> <th>Troops</th> <td class="unit"> 1 </td> <td class="unit none"> 0 </td> <td class="unit none"> 0 </td> <td class="unit none"> 0 </td> <td class="unit none"> 0 </td> <td class="unit none"> 0 </td> <td class="unit none"> 0 </td> <td class="unit none"> 0 </td> <td class="unit none"> 0 </td> <td class="unit none"> 0 </td> <td class="unit none last"> 0 </td> </tr> </tbody> <tbody class="infos"> <tr> <th>Arrival</th> <td colspan="11"> <div class="in">in&nbsp;<span class="timer" counting="down" value="246">0:04:06</span>&nbsp;hrs.</div> <div class="at"><span>at&nbsp;14:23:09</span><span> </span></div> </td> </tr> </tbody> </table> HTML; $dom = new DOMDocument; libxml_use_internal_errors(true); $dom->loadHTML($html); $xpath = new DOMXPath($dom); $tablePath = $xpath->query("//table[contains(@class, 'troop_details') and contains(@class, 'inAttack')]")[0]->getNodePath(); $xy = ltrim($xpath->query("$tablePath//span[@class='coordinateX']")[0]->nodeValue, '(') . ' ' . rtrim($xpath->query("$tablePath//span[@class='coordinateY']")[0]->nodeValue, ')'); $units = []; foreach ($xpath->query("$tablePath//tbody[contains(@class, 'units') and contains(@class, 'last')]//td[contains(@class, 'unit')]/text()") as $unit) { $units[] = trim($unit->nodeValue); } var_export($xy); echo "\n"; var_export(implode(' ', $units));
Output for 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
'‭0‬ ‭−‭28‬‬' '1 0 0 0 0 0 0 0 0 0 0'
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 '‭0‬ ‭−‭28‬‬' '1 0 0 0 0 0 0 0 0 0 0'

preferences:
172.79 ms | 402 KiB | 154 Q