AL-zami
AL-zami

Reputation: 9066

get whitespace back from value that is raw url encoded?

Here i have a value which have a white space.I passed the value using rawurlencode().But when i want to use the value in sql in database query ,i can't escape the "%20" which is added instead of white space

<a href =<?php echo "www.example.com?val =".rawurlencode("al zami") ;>click</a>

In backend i used $_GET['val'] ..but it has something like "al%20zami" .How to escape them in $_GET variable

Upvotes: 1

Views: 57

Answers (3)

Arzon Barua
Arzon Barua

Reputation: 514

use the following code. here urldecode decodes any %## encoding in the given string.

echo urldecode($_GET['val']);

Ref: php Manual

Upvotes: 1

ChristianF
ChristianF

Reputation: 2061

I suspect you're a bit confused with your terminology here, as the %20 is already escaped. What you seem to be asking, as far as I understand your question, is how to unescape it.

For that question the PHP manual for rawurlencode() holds the answer. Just remember to read the entire page, and read it carefully.

That being said. The fact that you get URL-escaped values inside your $_GET array, seems to indicate that you might have some additional problems in your code.
Normally the escaped values are automatically translated by the server when it receives them from the client, and as such manually unescaping them should never be necessary in most cases.

So please post an complete example of your code, which highlights the problem from start to to end. If you do that, we can help you find and fix the true problem. Not just the symptoms.

Upvotes: 1

Xenos
Xenos

Reputation: 3507

You have messed up with the code. Fix the useless spaces, add the quotes around your attribute, and close the PHP tag.

<a href="<?php echo "?val=".rawurlencode("al zami"); ?>">click</a>
<?php echo $_GET['val']; ?>

Upvotes: 0

Related Questions