Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement URLEncode in HTML

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report