MonkeyBlue MonkeyBlue - 1 year ago 141
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

Answer Source
$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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download