Hey, say I have a url just being passed through my php is there any easy way to get some GET variables that are being passed through it? It's not the actual url of the page or anything.
like a just have a string containing
http://www.somesite.com/index.php?url=var&file_id=var&test=var
Whats the best way to get the values for those variables?
Any word after the question mark (?) in a URL is considered to be a parameter which can hold values. The value for the corresponding parameter is given after the symbol "equals" (=). Multiple parameters can be passed through the URL by separating them with multiple "&".
PHP $_GET is a PHP super global variable which is used to collect form data after submitting an HTML form with method="get". $_GET can also collect data sent in the URL. Assume we have an HTML page that contains a hyperlink with parameters: <html>
parse_str(parse_url($url, PHP_URL_QUERY), $array)
, see the manpage for parse_str for more info.
$href = 'http://www.somesite.com/index.php?url=var&file_id=var&test=var';
$url = parse_url($href);
print_r($url);
/* Array
(
[scheme] => http
[host] => www.somesite.com
[path] => /index.php
[query] => url=var&file_id=var&test=var
) */
$query = array();
parse_str($url['query'], $query);
print_r($query);
/* Array
(
[url] => var
[file_id] => var
[test] => var
) */
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With