Difference between urlencode and urldecode

urlencode() function

This function is used to encode a string that can be used in a url. It encodes the same way posted data from the web page is encoded. It returns the encoded string.

Syntax:-


urlencode($string_value);

Example:-


<?php
$userName="John Taylor";
echo urlencode($userName);
?>
John+Taylor

Now, you can use urlencode() into URL


<?php
$userName="John Taylor";
echo '<a href="abc.php?uname='.urlencode($userName).'">URL</a>';
?>

urldecode() function

this function is used to decode the encoded string which is created by urlencode() function.
Syntax:-


urldecode($encoded_string_value);

Example:-


<?php
$userName="John Taylor";
echo $encodedUserName= urlencode($userName);  // John-Taylor
echo urldecode($encodedUserName);  // John Taylor
?>