PHP – URL Encode and Decode

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 = "https://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:

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.