[Solved] striping a URL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Addos
Forum Contributor
Posts: 305
Joined: Mon Jan 17, 2005 4:13 pm

[Solved] striping a URL

Post 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
Last edited by Addos on Wed Apr 23, 2008 5:09 pm, edited 1 time in total.
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: striping a URL

Post 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'];
Addos
Forum Contributor
Posts: 305
Joined: Mon Jan 17, 2005 4:13 pm

Re: striping a URL

Post by Addos »

Thank you very much that worked a treat and I never knew it existed.
Thanks again.
Post Reply