我希望製作一個能夠理解分頁的小腳本,以便我永久地輸入並提前分頁。如何製作一個能夠理解分頁的腳本
我輸入例如,2串:
hello14.com/14/oijosij
hello14.com/15/oijosij
腳本應該輸出:
hello14.com/14/oijosij
hello14.com/15/oijosij
hello14.com/16/oijosij
hello14.com/17/oijosij
hello14.com/18/oijosij
hello14.com/19/oijosij
,永遠,永遠。
它必須能夠處理很多網址變體,而不僅僅是這種特殊情況。
如果你看看我的代碼,你會發現我遇到了麻煩。 它檢測是否有分頁的網址,但我不知道如何檢測分頁位置的正確位置。 我不能爆炸找到的分頁號碼,這將導致錯誤,因爲我的示例包含URL中其他地方的第一個分頁號碼。
$string1 = "hello14.com/14/oijosij";
$string2 = "hello14.com/15/oijosij";
// match all spans of numbers
preg_match_all("/[0-9]{1,}/", $string1, $out);
preg_match_all("/[0-9]{1,}/", $string2, $out2);
// loop through all spans of numbers found in string 1
for ($loop = 0; $loop < count($out[0]); $loop++) {
if ($out2[0][$loop] - $out[0][$loop] == 1) {
echo "we have pagination. ".$out[0][$loop]." and ".$out2[0][$loop];
// but how can i go about it here?
}
}
'[0-9] {1,}' - >'\ d +' – alex
是什麼問題? – arunkumar
上面腳本的輸出最後將是:'hello1.com/14/oijosij'' hello1.com/15/oijosij'' hello1.com/16/oijosij'' hello1.com/17/oijosij'和等等。是不是很清楚,即時對不起 –