user3220399
user3220399

Reputation: 1

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.

<?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++;
}

?>

Upvotes: 0

Views: 61

Answers (1)

Tobias Golbs
Tobias Golbs

Reputation: 4616

Perhaps use your iterator to access the correct $results entry:

$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>';
}

Upvotes: 1

Related Questions