still wondering

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
lc
Forum Contributor
Posts: 188
Joined: Tue Apr 23, 2002 6:45 pm
Location: Netherlands

still wondering

Post by lc »

Someone posted a topic on the last forum asking about a link he encountered.

It showed something like index.php?1,3,4,5,3 in the adress bar.

Right now my stuff is all like indexp.php?id=5&blabla=blabla and such very long strings.

Can someone perhaps explain how the nice thing he saw works?

LC
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

doing a parse_url($url) will put everything following the ' ? ' into an array (i.e. parsed_url[query])
lc
Forum Contributor
Posts: 188
Joined: Tue Apr 23, 2002 6:45 pm
Location: Netherlands

Post by lc »

Well ok I had a good look at that on php.net but am still not entirely sure how to implement this.

Can you or someone just gimme a simple bit of code as an example?
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

lets say you have this URL:
$url = "http://www.domain.com/something.php?1,2,3,4,5";

doing a parser_url will give you an array:
$url_array = parse_url($url);

everything following the ' ? ' in the url will be stored as such:
$url_array[query]; //contains "1,2,3,4,5"
lc
Forum Contributor
Posts: 188
Joined: Tue Apr 23, 2002 6:45 pm
Location: Netherlands

Post by lc »

Right well I got that far... but then what... you have a variable called $query that contains the string 1,2,3,4,5

What do you do with that? I'm not familliar with that sort of string yet.. I've only worked with exploding arrays in while loops and such.
User avatar
enygma
Site Admin
Posts: 175
Joined: Fri Apr 19, 2002 8:29 am
Location: Dallas, Tx

Post by enygma »

just explode(",",$query)
then, volia, you have your parts....
lc
Forum Contributor
Posts: 188
Joined: Tue Apr 23, 2002 6:45 pm
Location: Netherlands

Post by lc »

Right... that's all... cool. I should have known that. Just never used commas to sepparate data ;)

Coolness thx
bjg
Forum Newbie
Posts: 15
Joined: Tue Jun 10, 2003 9:42 am
Location: .au

Post by bjg »

You can just use $_SERVER['QUERY_STRING'] without the need of parse_url().

Code: Select all

$parts = explode(',', $_SERVERї'QUERY_STRING']);
print_r($parts);

// Array ( ї0] => 1 ї1] => 2 ї2] => 3 ї3] => 4 ї4] => 5 )
That's via file.php?1,2,3,4,5
Post Reply