Page 1 of 1

[Solved] striping a URL

Posted: Wed Apr 23, 2008 4:16 pm
by Addos
I need to return the NewsID numeric value of 60 from this string mysite/details.php?NewsId=60&sweetid=2791992

I have to use $_GET["returnurl"] ; to return the url but I’m really not sure what is the best way to strip this string to just find the value of ā€˜60’ especially as this number could grow to 100's or more digits as the cart grows.

Can anyone suggest what I can do and what is the best way to strip this without problems later on?
Thank you

Re: striping a URL

Posted: Wed Apr 23, 2008 4:32 pm
by EverLearning
If I understood what you want correctly, you can use parse_str() and parse_url() to get what you need

Code: Select all

$url = 'mysite/details.php?NewsId=60&sweetid=2791992';
$info = parse_url($url);
parse_str($info['query'], $output);
echo $output['NewsId'];

Re: striping a URL

Posted: Wed Apr 23, 2008 5:08 pm
by Addos
Thank you very much that worked a treat and I never knew it existed.
Thanks again.