如何获取具有特定类名(例如)的所有行:
<tr class="dailyeventtext" bgcolor="#cfcfcf" valign="top">
然后将该行中的每个单元格放入数组中?
我使用了cURL从客户端服务器获取页面。
如何获取具有特定类名(例如)的所有行:
<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');
}
}
array_map()
函数映射列,返回textContent
属性即可。 - alex