[英]How to check table tr th/td exist in the page, php
I am trying to verify table
tr
th
/ td
or dl
dt
/ dd
exist or not in the page. 我试图验证
table
tr
th
/ td
或dl
dt
/ dd
存在于页面中。 So I tried to do something like below. 因此,我尝试执行以下操作。
foreach($links as $k => $val){
$html = file_get_contents($val);
if (strpos($val, "</table>") !== false) {
echo "table exist";
}
elseif(strpos($val, "</dl>")!== false){
echo "dl exist";
}
}
But it's not working. 但这不起作用。 Any possible way to verify html has certain elements?
任何可能的方法来验证html具有某些元素? Or is html has certain amount elements.
还是html有一定数量的元素。 for example more than 5
th
or more than 5 dd
例如多于5
th
或多于5 dd
You can use getElementsByTagName
of DOM 您可以使用DOM的
getElementsByTagName
$dom = new DOMDocument();
$dom->loadHTMLFile('filename.html');
$tableRow = $dom->getElementsByTagName('tr');
foreach ($tableRow as $tr) {
echo $tr->nodeValue;
echo $tableRow->length;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.