【发布时间】:2013-11-26 01:16:35
【问题描述】:
我有 php 函数从某个页面获取项目,该项目有分页
function get_content($link){
$string = file_get_contents($link);
$regex = '/https?\:\/\/[^\" ]+/i';
preg_match_all($regex, $string, $matches);
//this is important
foreach($matches as $final){
$newarray[] = $final;
}
if(strpos($string,'Next Page')){ //asumme the pagination is http://someserver.com/content.php?page=2
get_content($link);
}
return $newarray;
}
问题:
这种情况可以使用循环函数吗?
当我尝试时,为什么我只得到一页数组?我的意思是,如果有 5 个页面并且每个页面有 50 个链接,那么当我尝试打印结果时,我只会得到 50 个链接,而不是 250 个。
谢谢
【问题讨论】:
-
你为什么使用正则表达式来解析这个而不是
$_GET?使用起来要容易得多。 -
对不起伙计,我忘记了,我创建的功能是从页面中提取链接,页面有分页。假设页面有 5 页,所以我只获取 5 次内容并将所有 URL 保存在“$newarray”数组中。谢谢
标签: php regex arrays function loops