我有这个代码,它假设从HOME |获取数据并安排在表格中绘图| AWAY,当您查看代码时,您会发现count变量被赋予一个静态变量,当获取的值的数量将大于指定的变量时,它将带来问题。所以我需要的帮助是如何确定的或者我将用什么函数来计算这个属性的元素数量
'div[data-gamename="1X2"'
如下面的代码所示,如何计算它们?
<?php
include('advanced_html_dom.php');
$html = file_get_html('your-url-here');
//Here is where should be a counter to be assigned to $count variable
$count = 450;
for ($i=0; $i<$count; $i+=3){
$dot = $html->find('div[data-gamename="1X2"]',$i);
echo " Home ".$dot."<br>";
}
//This codes will be re-written to look same like the above
//I left for reference so you can get picture what i mean
$dot2 = $html->find('div[data-gamename="1X2"]',1);
$dot3 = $html->find('div[data-gamename="1X2"]',2);
echo "Draw ".$dot2."<br>";
echo "Away ".$dot3."<br>";
$html->clear();
?>
知道如何实现这个吗?
答案 0 :(得分:1)
$numcounter = count($dot2 = $html->find('div[data-gamename="1X2"]'));
echo "Number of elements are ".$numcounter." ------";
这是未来参考的答案。应将$numcounter
变量分配给$count
变量,并从上面的代码中将其变为$count = $numcounter;