I need to extract an item id from a URL; the pattern is this
&R=10031004&, I mean, I need to extract the string within &R= and the other &
This is what I have so far, but I keep getting errors.
preg_match('^[&R=]+ &$',
"http://www.lapdirecciondemario.com/items.php&R=10031004&", $matches);
$host = $matches[0];
echo $host;
In contrast to the other answers, this will also match if the parameter
Ris preceded by a?instead of a&. If you know more about the length of the number, you can replace the+after[0-9]with{min,max}.This regular expression should be pretty robust and match all of these: