How can you get vars in url using php?

I have a url,

example.com/?/page1

and I want to find out what part of the GET URL is, for example:

?/page1

how to do it? for example, without having to break lines and stuff?

+1
source share
4 answers

The following variable will contain the entire query string (i.e., the part of the URL following the character?):

$_SERVER['QUERY_STRING']

If you're interested, the rest of the contents of the $ _SERVER array are listed in the PHP manual here .

+7
source

This is a weird GET url because the normal format is:

domain.com/page.html?a=1&b=2

PHPinfo will help a lot:

<?php phpinfo(); ?>

Relevance Result:

<?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'
?>
+2
source

, parse_url() parse_str(). , "" () .

http_build_query , .


 $url = "example.com/?/page1";
 $res = parse_url($url, PHP_URL_QUERY);
 print "Query:".$res."\n";

:

Query:/page1
+2
source
for($i = 0, $e = count($_GET[]); $i < $e; $i++) {
    echo $_GET[$i];
}
0
source

Source: https://habr.com/ru/post/1778722/


All Articles