PHP Function UrlEncode and UrlDecode
In most cases, you will need to pass data in the form of a URL to another page or function that needs to process it dynamically. This means that you will need to encode or decode those strings so they can be sent across the internet safely. There are two built in functions in PHP that you can use to do this, urlencode and urldecode.
Encoding a string for URLs basically means converting all characters that are outside the ASCII range to a '%' followed by 2 hex digits. This ensures that only characters in the ASCII range will be sent over the internet. It also prevents the use of unsafe characters, such as
You can use the urlencode() function to do this, but it is more common to use rawurlencode(). It uses the RFC 3986 standard and is what you would use if you are working with a $_GET variable (which PHP automatically urldecodes for you) or if your code requires that all strings be escaped before passing them to $_REQUEST.
When decoding a string for URLs, you use the urldecode() function. This will return the original string back to its normal form. This also decodes the space character so that it becomes a plus sign (+) according to the application/x-www-form-urlencoded MIME format and replaces other special characters with their hex codes except for -, _, and.