Shin Shin - 1 year ago 78
PHP Question

PHP: Get parameter from encoded url

I have this url:


How can I
site_id from this url?

Answer Source

If you know your url's will always be in this structure, you can parse it out with RegEx like so:

$url = '/?goto=%2Fr%2Faccount%2Findex%2Ecfm%3Fsite_id%3D87211';
preg_match('/site_id\%3D(\d+)/', $url, $matches);
$siteId = $matches[1];

It's searching for anything that matches site_id%3D and the numeric value that follows that.

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