简体   繁体   English

为什么它不返回while循环中的所有结果?

[英]Why isn't this returning all of the results in this while loop?

I'm trying to write a video ripper and my while loop is only returning 1 result. 我正在尝试编写视频开膛手,而我的while循环仅返回1个结果。

<?php

$url = 'http://www.SITE.com/categories/redhead';
$url2 = 'http://www.SITE.com/movies';
$search = file_get_contents($url);
$results = explode('"/movies', $search);
$count = count($results);
$i = 1;


while($i < 5) {
    $final = $url2 .$results[$i];
    $goodfinal = str_replace('">', ' ', $final);
    echo $goodfinal.'<br>';
    $i++;
}

?>

Perhaps use your iterator to access the correct $results entry: 也许使用迭代器来访问正确的$results条目:

$url = 'http://www.SITE.com/categories/redhead';
$url2 = 'http://www.SITE.com/movies';
$search = file_get_contents($url);
$results = explode('"/movies', $search);

$i = 0;
$length = count($results);
while($i < $length) {
    $final = $url2 .$results[$i];
    $goodfinal = str_replace('">', ' ', $final);
    echo $goodfinal.'<br>';
    $i++;
}

As an alternative you could loop over your results like this: 或者,您可以像这样遍历结果:

foreach($results as $result) {
    echo str_replace('">', ' ', $url2 . $result) . '<br>';
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM