gpt4 book ai didi

PHP 根据类名解析 HTML 行

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:09:53 25 4
gpt4 key购买 nike

如何获取具有特定类名的所有行,例如:

<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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com