<?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">
‭<span class="coordinates coordinatesWrapper coordinatesAligned coordinatesltr"><span class="coordinateX">(‭0‬</span><span class="coordinatePipe">|</span><span class="coordinateY">‭−‭28‬‬)</span></span>‬ </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 <span class="timer" counting="down" value="246">0:04:06</span> hrs.</div>
<div class="at"><span>at 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 git.master, git.master_jit, rfc.property-hooks
- '0 −28'
'1 0 0 0 0 0 0 0 0 0 0'
This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.
Active branches
Archived branches
Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page
preferences:
27.82 ms | 405 KiB | 5 Q