How to implement URLEncode in HTML
This article focuses on "how to implement URLEncode in HTML". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to implement URLEncode in HTML"!
LEncode: refers to a coding conversion method for Chinese characters in web page url. The most common way is to generate Encode-passed web page URL when inputting Chinese query in Baidu, Google and other search engines. There are generally two ways of URLEncode, one is the traditional GB2312-based Encode (Baidu, Yisou, etc.), the other is UTF-8-based Encode (Google, Yahoo, etc.). The following editor will explain how to implement URLEncode in HTML and how to implement URLEncode in PHP.
How to realize URLEncode in HTML
In the html file encoded as GB2312: http://s.jb51.net/ Chinese .rar-> browser automatically converted to-> http://s.jb51.net/%D6%D0%CE%C4.rar
Note: Firefox's Chinese URL support for GB2312's Encode is not good, because it defaults to UTF-8 encoding to send URL, but the ftp:// protocol can, I have tried, I think this should be regarded as a bug for Firefox.
In the html file encoded as UTF-8: http://s.jb51.net/ Chinese .rar-> browser automatically converted to-> http://s.jb51.net/%E4%B8%AD%E6%96%87.rar.
How to realize URLEncode in PHP
/ / Encode of GB2312
Echourlencode ("Chinese-_."). "\ n"; /% D6% D0% CE% C4Mai. +
Echourldecode ("% D6% D0% CE% C4MB."). "\ n"; / / Chinese-_.
Echorawurlencode ("Chinese-_.").\ n "; / /% D6%D0%CE%C4-_.%20
Echorawurldecode ("% D6% D0% CE% C4MB."). "\ n"; / / Chinese-_.
>
Except for "- _." All non-alphanumeric characters outside will be replaced with the percent sign "%" followed by two hexadecimal digits.
The difference between urlencode and rawurlencode: urlencode encodes spaces as the plus sign "+" and rawurlencode encodes the spaces as the plus sign "% 20".
If you want to use UTF-8 's Encode, there are two ways:
First, save the file as a UTF-8 file, directly use urlencode, rawurlencode.
Second, use mb_convert_encoding function:
$url=' http://s.jb51.net/ Chinese .rar'
Echourlencode (mb_convert_encoding ($url,'utf-8','gb2312')).\ n
Echorawurlencode (mb_convert_encoding ($url,'utf-8','gb2312')).\ n
/ / http%3A%2F%2Fs.jb51.net%2F%E4%B8%AD%E6%96%87.rar
>
Example:
Functionparseurl ($url= "")
{
$url=rawurlencode (mb_convert_encoding ($url,'gb2312','utf-8'))
$a=array ("3A", "2F", "40")
$b=array (":", "/", "@")
$url=str_replace ($a _
Return$url
}
$url= "ftp://ud03:password@s.jb51.net/ Chinese / Chinese .rar"
Echoparseurl ($url)
/ / ftp://ud03:password@s.jb51.net/%D6%D0%CE%C4/%D6%D0%CE%C4.rar
>
URLEncode in JavaScript:
For example:% E4%B8%AD%E6%96%87-_.%20%E4%B8%AD%E6%96%87-_.%20
EncodeURI does not encode the following characters: special characters such as ":", "/", ";", "", "@" and so on.
At this point, I believe you have a deeper understanding of "how to implement URLEncode in HTML". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!