Page 1 of 1

still wondering

Posted: Tue Apr 23, 2002 6:45 pm
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

Posted: Tue Apr 23, 2002 6:53 pm
by mydimension
doing a parse_url($url) will put everything following the ' ? ' into an array (i.e. parsed_url[query])

Posted: Wed Apr 24, 2002 8:38 am
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?

Posted: Wed Apr 24, 2002 10:09 am
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"

Posted: Wed Apr 24, 2002 3:55 pm
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.

Posted: Wed Apr 24, 2002 4:57 pm
by enygma
just explode(",",$query)
then, volia, you have your parts....

Posted: Wed Apr 24, 2002 6:44 pm
by lc
Right... that's all... cool. I should have known that. Just never used commas to sepparate data ;)

Coolness thx

Posted: Tue Jun 17, 2003 9:06 am
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