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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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