0

Im trying to send a query string in url

for ex : url : localhost/myfile.php?number=8777,+9822,+9883

in myfile.php when i give echo the query string :

echo $_REQUEST['number'];

output :

 8777,9822,9883

but the expected output is :

8777,+9822,+9883

How can i display + sign also.

UPDATE :

actually that url is web request from the android/ios device app,

im providing webservice in php,

so android/ios developers are sending request with a querystring contains + sign

so how can i handle this situation?

4
  • use the urlencode function to send such value Commented Jul 18, 2014 at 6:49
  • url encode your url.localhost/myfile.php?number=8777,%2B9822,%2B9883 Commented Jul 18, 2014 at 6:49
  • You have failed to understand HTTP. Punch out and go home. Commented Jul 18, 2014 at 6:51
  • please check my update in question Commented Jul 18, 2014 at 6:55

3 Answers 3

2
+ is reserved. PHP is correct in translating an unencoded + sign to a space.

You can use urlencode() urldecode() for this. The + must be submitted in PHP as the encoded value: %2B

Sign up to request clarification or add additional context in comments.

Comments

0

You should then use urlencode() function to create that url:

<?php

var_dump($_GET['number']);

echo 'http://localhost/myfile.php?number='.urlencode('8777,+9822,+9883');

EDIT

If this is url that you receiving and cannot do anything with that you can use for example:

echo substr($_SERVER['REQUEST_URI'],strpos($_SERVER['REQUEST_URI'],'=')+1);

and you will get

8777,+9822,+9883

Comments

0

Sorry, i dont know what you're trying to do, but here's a suggestion

// where base64_encode('8777,+9822,+9883') = ODc3NywrOTgyMiwrOTg4Mw

localhost/myfile.php?number=ODc3NywrOTgyMiwrOTg4Mw

// on myfile.php

echo base64_decode($_REQUEST['number']);

// this will output -> 8777,+9822,+9883

UPDATE --------------------------- if you have no other choice , you can use this

<?php
// get URL query string
$params = $_SERVER['QUERY_STRING']; 

// if you have $params = www.mydomain.com/myfile.php?number=9988,+9876,+8768
$temp = explode('=', $params);
echo $temp[1] .'<hr>';


// if you have $params = www.mydomain.com/myfile.php?number=9988,+9876,+8768&number2=123,+456,+789
$params2 = $_SERVER['QUERY_STRING']; 
$temp3 = explode('&', $params2);
foreach($temp3 as $val){
    $temp4 = explode('=', $val);
    // # // $GET = $temp4[0]; // if you need the GET VALUES
    $VALUE = $temp4[1];
    echo $VALUE .'<br>';
}
?>

Hope this helps.... :)

1 Comment

basically what the moto is : from an android/ios app, im getting a webrequest : like www.mydomain.com/myfile.php?number=9988,+9876,+8768 so i need to get all the numbers including +sign

Your Answer

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.