我要抓取与preg_match_all()
几页和数据保存到一个数组($matches
),网址是这样的: webpage.com/p/1
,并在年底的nuber是多少子页面并且必须随每次运行而改变。 我想过类似的东西(有10子页面):如何将数据推到阵列while循环PHP
$x = 1;
while ($x <= 10) {
$current_page = 'webpage.com/p/$x';
$subpage = file_get_contents($current_page);
preg_match_all('regexp', $subpage, $matches);
$matches = $matches[1];
$x++;
}
,但似乎像数组只包含从第一次运行的数据,我该怎么办错了吗?
'$匹配= $匹配[1]'你知道这个代码是什么? –
检查array_push()https://www.w3schools.com/php/func_array_push.asp – user1211
$匹配是一个字符串。你需要使用'$ allmatches [] = $ matches [1];'我的意思是匹配在最后一行。真令人费解的是,在两件事情上使用同一个名字。正如你可以看到这是一件坏事 – Andreas