3

I have this link:

www.mysite.com?a=abc+dfg

I would, in php, obtain the value: $_GET["a"].

But, in this way, i get the string "abc dfg", without the "+".

How can i do to get the entire value?

Josua Marcel C
  • 3,122
  • 6
  • 45
  • 87
user2520969
  • 1,389
  • 6
  • 20
  • 30
  • 3
    That *is* the entire value. If you want the plus sign to be preserved, you'll have to encode it in hexadecimal. Try `?a=abc%2Bdfg` – r3mainer Jul 03 '15 at 23:24
  • have you tried $string = urldecode($_GET['a']); ? – hiew1 Jul 03 '15 at 23:29
  • 1
    If you want to inspect the raw input and original encoding, that's in `$_SERVER["QUERY_STRING"]`. – mario Jul 03 '15 at 23:34

4 Answers4

1

Maybe you should encode somehow before create the URL. Take a look at this article at php manual website:

URLEncode Function

PHPCode

echo urlencode("asd+bbb"); //asd%2Bbbb

and URLDecode to get the results properly:

URLDecode Function

echo urldecode("asd%2Bbbb"); //asd+bbb
alysonsm
  • 1,465
  • 1
  • 12
  • 16
0

Before you pass it to your website

www.mysite.com?a=abc+dfg

you have to add "www.mysite.com?" . "a=" . urlencode($value);


After that your data on address url should be like

www.mysite.com?a=asd%2Bbbb

when you GET

You can call with urldecode($_GET["a"]);

The return should be abc+dfg

Josua Marcel C
  • 3,122
  • 6
  • 45
  • 87
0

This question is old but i would like to differ with most of the answers posted.

If you have abc+dfg you need to perform function urlencode(abc+dfg) to it.

then you will be able to get the plus sign using $_GET('a').

If you perform urldecode() it will give you abc dfg, without + sign.

You can verify my answer based on below code:

The file is named test.php:

 <?php

$question = "abc+dfg";

$ques_enc = urlencode($question);
echo "url encode";
echo "<br>";

echo "<a href='test.php?ques=$ques_enc'>
View question encode</a> ";
echo "<br>";
echo "<br>";

echo "no url encode";
echo "<br>";

echo "<a href='test.php?ques=$question'>
View question</a> ";
echo "<br>";
echo "<br>";


if(isset($_GET['ques'])){
  echo "no url decode";
  echo "<br>";

$ques = $_GET['ques'];
echo $ques;
echo "<br>";
echo "<br>";

}

if(isset($_GET['ques'])){

echo "url decode";

$ques = urldecode($_GET['ques']);
echo "<br>";

echo $ques;

}

Image with urlencode() clicked: enter image description here

Image without urlencode() clicked: enter image description here

As you can see from above if you encode and don't decode, you get the plus(+) sign. If you don't encode and don't decode, you don't get plus(+) sign

hardeep
  • 93
  • 2
  • 12
-1

The space is not a url friendly character. PHP's urlencode() function converts spaces to +

Try using urldecode()

echo urldecode($_GET["a"]);

http://php.net/manual/en/function.urldecode.php