如何获取具有特定类名的所有行,例如:
<tr class="dailyeventtext" bgcolor="#cfcfcf" valign="top">
然后将该行中的每个单元格放入一个数组中?
我使用 cURL 从客户端服务器获取页面。
最佳答案
$matches = array();
$dom = new DOMDocument;
$dom->loadHTML($html);
foreach($dom->getElementsByTagName('tr') as $tr) {
if ( ! $tr->hasAttribute('class')) {
continue;
}
$class = explode(' ', $tr->getAttribute('class'));
if (in_array('dailyeventtext', $class)) {
$matches[] = $tr->getElementsByTagName('td');
}
}
关于PHP 根据类名解析 HTML 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7550079/