I'm trying to replace a number in a string with another number by using regex. This should be super simple, but for some reason it's giving me grief today. "feed" in the string is dynamic and can contain letters or numbers only.
Here is what I've tried:
$new_number = 999;
$string = '/feed/page/1/?param=true';
preg_replace('/\/([0-9a-z])\/page\/([0-9])\/(.*)/i', '/$1/page/'.$new_number.'/$3', $string);
Should output: '/feed/page/999/?param=true'
/to delimit regex.'@/([0-9a-z]+)/page/([0-9]+)/(.*)@i'is sexier than'/\/([0-9a-z]+)\/page\/([0-9]+)\/(.*)/i'.