PHP – URL Encode and Decode

Special characters in URL are encoded according to RFC 3986. You could get the encoded URL by rawurlencode().

    <title>PHP - Encode and Decode URL</title>
    <h2 style="text-decoration: underline;">rawurlencode()</h2>
      $url = "密舒的BB/";
      print "<p>".rawurlencode($url)."</p>";
    <h2 style="text-decoration: underline;">rawurldecode()</h2>
      $url = rawurlencode($url);
      print "<p>".rawurldecode($url)."</p>";


As you can see above, you could obtain the Chinese characters and other special characters by rawurldecode(). Here is the result


Done =)


Leave a Reply

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

You are commenting using your 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.