我有一个html:
$content = "
<tr>
<td class="ttl"><a href="#">Colors</a></td>
<td class="nfo">Dark Grey, Rose Red, Blue, Brown, Sand White</td>
</tr>";
和代码php:
$dom = new DOMDocument();
@$dom->loadHTML($content);
$xpath = new DOMXPath($dom);
$attbs = $xpath->query("//td[@class='ttl']");
foreach($attbs as $a) {
print $a->nodeValue;
}
$values = $xpath->query("//td[@class='nfo']");
foreach($values as $v) {
print $v->nodeValue;
}
如何获得 2 td 的值但仅使用 1 foreach