Getting variables from STRING url in php

If I have a url that looks like that, the best way to read the value

http://www.domain.com/compute?value=2838

I tried parse_url(), but it gives me value=2838not2838

Edit: Note that I'm talking about a string, not a current url. I have a url stored in a string.

+3
source share
5 answers

You can use parse_urland then parse_strin the request.

<?php
$url = "http://www.domain.com/compute?value=2838";
$query = parse_url($url, PHP_URL_QUERY);
$vars = array();
parse_str($query, $vars);
print_r($vars);
?>

Print

Array
(
    [value] => 2838
)
+6
source

For http://www.domain.com/compute?value=2838you must use $_GET['value']to return 2838

+3
source
$uri = parse_url($uri);
parse_str($uri['query'], $params = array());

, parse_str() . script!

+1

parse_str ($ url) $value = 2838.

. http://php.net/manual/en/function.parse-str.php

0

GET,

echo "value = ".$_GET['value'];  
0

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


All Articles