3

If I have a url that looks like this, what's the best way to read the value

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

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

Edit: please note I'm talking about a string, not an actual url. I have the url stored in a string.

asked Dec 6, 2010 at 11:42
1

5 Answers 5

6

You can use parse_url and then parse_str on the query.

<?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);
?>

Prints:

Array
(
 [value] => 2838
)
answered Dec 6, 2010 at 11:49
3

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

answered Dec 6, 2010 at 11:43
0
1
$uri = parse_url($uri);
parse_str($uri['query'], $params = array());

Be careful if you use parse_str() without a second parameter. This may overwrite variables in your script!

answered Dec 6, 2010 at 11:46
0

parse_str($url) will give you $value = 2838.

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

answered Dec 6, 2010 at 11:46
0
0

You should use GET method e.g

echo "value = ".$_GET['value']; 
answered Dec 6, 2010 at 11:54

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.