Tool for encoding URL’s with urlencode() PHP function

urlencode() is a function that is helpful when displaying various URL’s especially in forums and social tools when we know nothing about URL’s that are going to be shared by users of our tool or website. Bear in mind that a link within href of <a href="...encoded url goes here...">...decoded string goes here...</a> should awlays be encoded however displayed text should be shown decoded since this is more user-friendly, and moreover people who would like to CTRL+C / CTRL+V such a link, won’t use misinterpreted URL. All in all functions urlencode() and urldecode() always come together.

urlencode is a PHP function which converts strings such as URL’s into a computer-friendly form.

 

Code example

<?php //returns urlencode of a string $str[] = "http://www.bing.com/search?q=jan+hvizdak
&qs=n&form=QBLH&pq=jan+hvizdak&sc=0-0&sp=-1&sk="; echo "Output is: ".htmlspecialchars(urlencode($str[0])); /*
http%3A%2F%2Fwww.bing.com%2Fsearch%3Fq%3D
jan+hvizdak%26qs%3Dn%26form%3DQBLH%26pq%3Djan+hvizdak%26sc%3D0-0%26sp%3D-1%26sk%3D */
?>

Other tools & help

If you need help with PHP scripting, Apache setup and server-related situations, drop me a line. You’re also welcome to visit other tools - they’re listed below.