我正在尝试编写一个视频开膛手,而我的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++;
}
?>
答案 0 :(得分:1)
也许使用你的迭代器来访问正确的$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++;
}
作为替代方案,您可以像这样循环结果:
foreach($results as $result) {
echo str_replace('">', ' ', $url2 . $result) . '<br>';
}