looking for a function to parse URL parameters

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
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

looking for a function to parse URL parameters

Post by jasongr »

Hello

I was wondering if anyone knows if there is a PHP function that takes as input a URL string, parses it and returns an array of all the parameters in the string.

Here is an example:

"text.html?a=1&b=2&c=3"

output would be:
array('a' => 1, 'b' => 2, 'c' => 3)

regards
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

$_SERVER['QUERY_STRING'] would be may be helpful...
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

Post by jasongr »

I have found parse_str() to be useful
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Or simply:

Code: Select all

print_r($_GET);
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

Post by jasongr »

Actually I was looking for a function that will parse the string into an array I can later manipulate, not just to see it
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you can play with the $_GET array all you want.. it's writable.
Post Reply