I have a url,
example.com/?/page1
and i want to find out what the GET part of the url is, for example:
?/page1
how do i do this? like, without having to split strings and stuff?
I have a url,
example.com/?/page1
and i want to find out what the GET part of the url is, for example:
?/page1
how do i do this? like, without having to split strings and stuff?
The following variable will contain the entirety of the query string (that is, the portion of the url following the ? character):
$_SERVER['QUERY_STRING']
If you're curious about the rest of the contents of the $_SERVER array, they're listed in the PHP manual here.
$_GET is an associative array of key values that are passed from the user's request. You can see its contents by doing:
print_r($_GET);
http://us3.php.net/manual/en/reserved.variables.get.php
EDIT: For convenience you may want to pass key=value pairs separated by ampersands. E.g.,
example.com/?page=1
That is a strange GET URL because the normal format is:
domain.com/page.html?a=1&b=2
PHPinfo will help a whole lot:
<?php phpinfo(); ?>
Output of relevance:
<?php
// imagine URL is 'domain.com/page.html?a=1&b=2'
phpinfo();
echo $_GET['a']; // echoes '1'
echo $_GET['b']; // echoes '2'
echo $_SERVER['QUERY_STRING']; // echoes 'a=1&b=2'
echo $_SERVER['REQUEST_URI']; // echoes '/path/to/page.php?a=1&b=2'
?>
Sounds to me like you want to look up parse_url() and parse_str(). Of course, these will 'split' the string(s) behind the scenes.
You can then use http_build_query to rebuild the query, if required.
$url = "example.com/?/page1";
$res = parse_url($url, PHP_URL_QUERY);
print "Query:".$res."\n";
Output is:
Query:/page1