如何限制php dom解析结果
我放弃了一些结果,当我放弃时,我得到了50个结果。我想要 要只显示前20个结果,下面是代码,如何限制结果如何限制php dom解析结果,php,parsing,dom,html-parsing,Php,Parsing,Dom,Html Parsing,我放弃了一些结果,当我放弃时,我得到了50个结果。我想要 要只显示前20个结果,下面是代码,如何限制结果 使用变量继续计算结果,并在计数为20时立即从for循环中断 <?php require 'simple_html_dom.php'; $url = "http://espncricinfo.com/scores/match-100007"; $html = file_get_html( $url ); $posts = $html->find('di
使用变量继续计算结果,并在计数为
20
时立即从for循环中断
<?php
require 'simple_html_dom.php';
$url = "http://espncricinfo.com/scores/match-100007";
$html = file_get_html( $url );
$posts = $html->find('div[type=tuple]');
$count = 0;
foreach ( $posts as $post ) {
$count++
$matchtitle = $post->find('span[class=desigd]',0);
$matchdate = $post->find('span[class=date]',0);
echo $matchtitle;
echo $matchdate;
if($count == 20)
{
exit();
}
}
?>
谢谢,先生,它正在工作。小修正$count++应为$count++;
<?php
require 'simple_html_dom.php';
$url = "http://espncricinfo.com/scores/match-100007";
$html = file_get_html( $url );
$posts = $html->find('div[type=tuple]');
$count = 0;
foreach ( $posts as $post ) {
$count++
$matchtitle = $post->find('span[class=desigd]',0);
$matchdate = $post->find('span[class=date]',0);
echo $matchtitle;
echo $matchdate;
if($count == 20)
{
exit();
}
}
?>