php for循环不起作用 - 第二个循环在第一个循环后不起作用

时间:2016-12-24 12:45:40

标签: php for-loop

我在php中有两个for循环。仅输出第一个循环。为什么忽略第二个for循环?我花时间看这段代码并尝试不同的东西,所以任何想法都会受到高度赞赏。我已经独立尝试了每个循环,它们工作,所以我知道代码是正确的。

这个问题似乎就在我要求第二个循环在第一个循环之后运行的时候。

非常感谢

$str_test = file_get_contents("...");    
$count = 0;
$count2=0;


for($y = 0; $y<strlen($str_test); $y++)
{
      $pos2 = strpos($str_test, "<div class=\"f-reviews-title f-reviews-title--noSpace\" itemprop=\"author\">",$count2);
      if($pos2 == $count2){
           $pos2 = substr($str_test, $pos2+196);       
           $pos3 = strpos($pos2, "</a>");
           $author= substr($pos2, 0, $pos3);
           echo '<br>';
           echo $author;
           echo '<br>';
       }
       $count2++;
}

for($i = 0; $i<strlen($str_test); $i++)
{
     $pos = strpos($str_test, "<p class=\"f-reviews-txt\" itemprop=\"reviewBody\">", $count);
     if($pos == $count){    
          $pos= substr($str_test, $pos+47);
          $pos4 = strpos($pos, "</p>");
          $review= substr($pos, 0, $pos4);          
          echo '<br>';
          echo $review;
          echo '<br>';
     }
     $count++;
}

0 个答案:

没有答案