Shin Shin - 8 months ago 34
PHP Question

PHP: Get parameter from encoded url

I have this url:


How can I
site_id from this url?


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.