Php urlencode and rawurlencode tutorial

Source: Internet
Author: User
Tags rfc urlencode alphanumeric characters
Rawurlencode
(PHP 4 and PHP 5)

Rawurlencode-URL encoding according to RFC 1738

Description
String rawurlencode (string $ str)
Encode a specific string according to RFC 1738 of & raquo.

Parameters

Str
Encode the URL.


Return value
Returns all non-alphanumeric characters in a string -_. It is replaced with a percent sign (%) followed by two hexadecimal numbers. This is the encoding description & raquo; RFC 1738 to protect the conversion and nature of the transport media that literal characters are interpreted as special URLs separated and protected URLs damaged (such as some email systems ).

Instance

For example, #1 includes an FTP website with a password

<? Php
$ A = explode ('&', $ QUERY_STRING );
$ I = 0;
While ($ I <count ($ )){
$ B = split ('=', $ a [$ I]);
Echo 'Value for parameter ', htmlspecialchars (urldecode ($ B [0]),
'Is, htmlspecialchars (urldecode ($ B [1]), "<br/> n ";
$ I ++;
}
?>

Urlencode
(PHP 4 and PHP 5)

URL encoded string

Description
Urlencode string (string $ str)
This function allows you to easily encode a string as part of a URL to be queried and pass the next page of a variable.

Parameters

Str
String encoding.


Return value
Returns all non-alphanumeric characters in a string -_. Signs of being replaced with a percent sign (%) followed by two hexadecimal numbers and spaces encoded as the plus sign (+. This is the same encoding method, from the published data encoding WWW form, which is the same method in the application/x www form of the urlencoded media type. This is different from the historical reasons in Reference & raquo; RFC 1738 encoding (see rawurlencode (), where space encoding is a plus sign (+.

Instance

Example of urlencode () in #1

<? Php
Echo '<a href = "mycgi? Foo = ', urlencode ($ userinput),' "> ';
?>


Example #2 urlencode () and htmlentities () example

<? Php
$ Query_string = 'foo = '. urlencode ($ foo).' & bar = '. urlencode ($ bar );
Echo '<a href = "mycgi? '. Htmlentities ($ query_string).' "> ';
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.