使用php获取页面并计算html表中的行数

使用php获取页面并计算html表中的行数,php,html,dom,Php,Html,Dom,帮我查一下密码 $homepage = file_get_contents('index.html'); foreach($homepage->find('table') as $table){ // returns all the <tr> tag inside $table $all_trs = $table->find('tr'); $count = count($all_trs); echo $count; } $hom

帮我查一下密码

$homepage = file_get_contents('index.html');
foreach($homepage->find('table') as $table){ 
     // returns all the <tr> tag inside $table
     $all_trs = $table->find('tr');
     $count = count($all_trs);
     echo $count;
}
$homepage=file\u get\u contents('index.html');
foreach($homepage->find('table')作为$table){
//返回$table中的所有标记
$all_trs=$table->find('tr');
$count=count($all_trs);
echo$count;
}

我正在尝试获取index.html的内容,然后计算tr标记的数量,但上面的代码不起作用。

我不完全确定这段代码是在什么上下文中,但您可以使用
file\u get\u contents()
substr\u count()

echo substr\u count(strtolower(文件获取内容('index.html')),'';
您可以将API用于此目的:

$dom = new DOMDocument;
$dom->loadHTMLFile('index.html');
$tr_count = $dom->getElementsByTagName('tr')->length;
$dom = new DOMDocument;
$dom->loadHTMLFile('index.html');
$tr_count = $dom->getElementsByTagName('tr')->length;