MonkeyBlue MonkeyBlue - 2 months ago 12
PHP Question

PHP Using RegEx to get substring of a string

I'm looking for an way to parse a substring using PHP, and have come across preg_match however I can't seem to work out the rule that I need.

I am parsing a web page and need to grab a numeric value from the string, the string is like this


I need to be able to obtain this part of the string:


Thanks Aaron

$matches = array();
preg_match('/id=([0-9]+)\?/', $url, $matches);

This is safe for if the format changes. slandau's answer won't work if you ever have any other numbers in the URL.