Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing & in query string

Tags:

php

I want to pass '&' operator in query string. I tried to use urlencode and urldecode but its not working. I am doing this:

$abc="A & B";
$abc2=urlencode($abc);

Then I am passing the value like this

<a href="hello.php?say=<?php echo $abc2 ?>"><?php echo $abc;?></a>

and getting value on next page as

$abc=$_GET['say'];
$abcd=urldecode($abc');
echo $abcd;

but the output is not A & B

What am I doing wrong?

like image 879
Manoj Kumar Avatar asked May 16 '26 21:05

Manoj Kumar


1 Answers

Basically it should work I tried the following on my webserver:

$a = 'A & B';
echo urlencode($a);
echo '<br />';
echo urldecode(urlencode($a));

Output

A+%26+B
A & B

I guess you have another logically or syntax error which causes your & not to be decoded correctly, in your code there's an apostroph in your urldecode()-syntax.

Is that all of your code or are you using a "similiar" one? your original code would be useful then.

like image 163
peipst9lker Avatar answered May 18 '26 11:05

peipst9lker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!