主题
  • 默认模式
  • 浅蓝色模式
  • 淡红色模式
  • 深夜模式

HTML URL 编码参考手册

URL - 统一资源定位器(Uniform Resource Locator)

Web 浏览器使用 URL 从 Web 服务器请求页面。

URL 是网页的地址,比如:https://www.kaicz.com。


URL 编码(百分比编码)

URL 编码将字符转换为可通过因特网传输的格式。

URL 只能使用 ASCII 字符集 通过因特网进行发送。

由于 URL 通常包含 ASCII 集之外的字符,因此必须将 URL 转换为有效的 ASCII 格式。

URL 编码使用后跟十六进制数字的 "%" 替代不安全的 ASCII 字符。

URL 不能包含空格。URL 编码通常使用加号(+)或 %20 替代空格。


亲自试一试

如果您点击下面的“提交”按钮,浏览器将对输入进行 URL 编码,然后再将其发送到服务器。服务器上的页面将显示收到的输入。

请尝试其他的输入,然后再次点击提交。


URL 编码函数

在 JavaScript、PHP 和 ASP 中,有一些函数可用于对字符串进行 URL 编码。

PHP 有rawurlencode()函数,而 ASP 有Server.URLEncode()函数。

在 JavaScript 中,您可以使用encodeURIComponent()函数。

请点击"URL 编码"按钮,来查看 JavaScript 函数如何编码文本。

注释:JavaScript 函数把空格编码为 %20。


ASCII 编码参考手册

浏览器将根据页面中使用的字符集对输入进行编码。

HTML5 中的默认字符集为 UTF-8:

ASCII 字符 描述 URL-encoding
NUL null character %00
SOH start of header %01
STX start of text %02
ETX end of text %03
EOT end of transmission %04
ENQ enquiry %05
ACK acknowledge %06
BEL bell (ring) %07
BS backspace %08
HT horizontal tab %09
LF line feed %0A
VT vertical tab %0B
FF form feed %0C
CR carriage return %0D
SO shift out %0E
SI shift in %0F
DLE data link escape %10
DC1 device control 1 %11
DC2 device control 2 %12
DC3 device control 3 %13
DC4 device control 4 %14
NAK negative acknowledge %15
SYN synchronize %16
ETB end transmission block %17
CAN cancel %18
EM end of medium %19
SUB substitute %1A
ESC escape %1B
FS file separator %1C
GS group separator %1D
RS record separator %1E
US unit separator %1F

URL 编码参考手册

ASCII 控制字符 %00-%1F 最初旨在控制硬件设备。

控制字符与 URL 无关:

ASCII 字符 描述 URL-encoding
NUL null character %00
SOH start of header %01
STX start of text %02
ETX end of text %03
EOT end of transmission %04
ENQ enquiry %05
ACK acknowledge %06
BEL bell (ring) %07
BS backspace %08
HT horizontal tab %09
LF line feed %0A
VT vertical tab %0B
FF form feed %0C
CR carriage return %0D
SO shift out %0E
SI shift in %0F
DLE data link escape %10
DC1 device control 1 %11
DC2 device control 2 %12
DC3 device control 3 %13
DC4 device control 4 %14
NAK negative acknowledge %15
SYN synchronize %16
ETB end transmission block %17
CAN cancel %18
EM end of medium %19
SUB substitute %1A
ESC escape %1B
FS file separator %1C
GS group separator %1D
RS record separator %1E
US unit separator %1F



评论区 0
发表评论