Quantcast
Channel: Eureka! » RFC 3986
Viewing all articles
Browse latest Browse all 2

PHP – URL Encode and Decode

$
0
0

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:


Filed under: PHP Tagged: PHP, Postaday2011, RFC 3986

Viewing all articles
Browse latest Browse all 2

Trending Articles