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?
}
}
I’m sure there must be a very different&easier approach to this, but I did what I could with what I knew