Special characters in URL are encoded according to RFC 3986. You could get the encoded URL by rawurlencode().
<html> <head> <title>PHP - Encode and Decode URL</title> </head> <body> <h2 style="text-decoration: underline;">rawurlencode()</h2> <?php $url = "http://ykyuen.wordpress.com/2009/10/11/密舒的BB/"; print "<p>".rawurlencode($url)."</p>"; ?> <br/> <h2 style="text-decoration: underline;">rawurldecode()</h2> <?php $url = rawurlencode($url); print "<p>".rawurldecode($url)."</p>"; ?> </body> </html>
As you can see above, you could obtain the Chinese characters and other special characters by rawurldecode(). Here is the result
Done =)
Reference:
- PHP – rawurldecode
- PHP – rawurlencode
- Wikpedia – URL normalization
- Uniform Resource Identifier (URI): Generic Syntax
Filed under: PHP Tagged: PHP, Postaday2011, RFC 3986
