我想从特定行中获取<td>
,但我总是遇到Warning: Invalid argument supplied for foreach()
错误。警告:为foreach()提供的无效参数PHP DOM
我的代码:
$dom = new domDocument;
@$dom->loadHTML($notes); #$notes - value of textarea
$dom->preserveWhiteSpace = false;
$rows = $dom->getElementsByTagName('tr');
$moths = $rows->item(0)->nodeValue; #first row
$mothlast = $rows->item($rows->length - 1)->nodeValue; #lastrow
foreach ($moths as $moth)
{
$cols_mother = $moth->getElementsByTagName('td'); trying to get the columns of the first row of table
$rli_mother = strip_tags($cols_mother->item(0)->nodeValue);
echo $rli_mother; #first row
}
任何帮助将欣然赞赏。谢谢!!!
确保'$ moths'实际上有一个值,并且在尝试循环它之前是一个数组 –
是的它有一个值。它实际上是我桌子的第一排。 – user3310979
你确定吗? PHP似乎并不这么认为。 –