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?
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?
Maybe you should encode somehow before create the URL. Take a look at this article at php manual website:
PHPCode
echo urlencode("asd+bbb"); //asd%2Bbbb
and URLDecode to get the results properly:
echo urldecode("asd%2Bbbb"); //asd+bbb
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
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:
Image without urlencode() clicked:
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
The space is not a url friendly character. PHP's urlencode() function converts spaces to +
Try using urldecode()
echo urldecode($_GET["a"]);