如何制作一个能够理解分页的脚本
我希望制作一个小脚本来理解我输入的网址的分页并永远推进分页。
我的输入示例,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?
}
}
i looking to make a small script that will understand pagination of urls i input and advance the pagination forever.
my input example, 2 strings:
hello14.com/14/oijosij
hello14.com/15/oijosij
script should output:
hello14.com/14/oijosij
hello14.com/15/oijosij
hello14.com/16/oijosij
hello14.com/17/oijosij
hello14.com/18/oijosij
hello14.com/19/oijosij
and forever and forever.
it must be able to handle many variations of urls, not just this spesific case.
if you look at my code below, you see where i run into trouble.
it detects if there IS pagination in the urls, but i dont know how to detect the right position of where the pagination is located.
i cannot just explode the pagination number found, that will result in error, as my example contains the first pagination-number also elsewhere in the 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?
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我确信一定有一种非常不同且更简单的方法来解决这个问题,但我用我所知道的做了我能做的
I'm sure there must be a very different&easier approach to this, but I did what I could with what I knew