Search code examples
phpurl-encoding

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


Solution

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

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

    Ref: php Manual