Search notes:

PHP code snippets: the urldecode() function

urldecode() can be used to decode percent encoded characters of an URI.
The following example tries to demonstrate that the values in the super global associative array $_GET is already url-decoded, but not the value of $_SERVER['QUERY_STRING'].
<?php
print('<html><head>
<meta charset="utf-8">
<title>urldecode</title></head><body>
');

printf('<form>
   <input type="text" name="words" value="%s" />
   <input type="submit"/>
</form>', htmlentities(
           array_key_exists('words', $_GET) ? $_GET ['words'] : "O'briƤn & company"
          )
);

print("<hr><table border=1 style='border-collapse:collapse'>");
printf("<tr><td>\$_GET['words']</td><td>%s</td></tr>"                     ,           htmlentities(array_key_exists('words'       , $_GET   ) ? $_GET   ['words'       ] : "") );
printf("<tr><td>\$_SERVER['QUERY_STRING']</td><td>%s</td></tr>"           ,           htmlentities(array_key_exists('QUERY_STRING', $_SERVER) ? $_SERVER['QUERY_STRING'] : "") );
printf("<tr><td>urldecode(\$_SERVER['QUERY_STRING'])</td><td>%s</td></tr>", urldecode(htmlentities(array_key_exists('QUERY_STRING', $_SERVER) ? $_SERVER['QUERY_STRING'] : "")));
print("</table>");

print("</body></html>");
?>
Github repository about-php, path: /urldecode.php

See also

htmlspecialchars()
Other PHP snippets.

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758205951, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/web/php/snippets/urldecode(71): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78