JavaScript encode and escape functions
The encodeURI, encodeURIComponent and escape functions convert special characters in URLs and other URIs by percent encoding the special characters.
encodeURI
function is used to encode an entire unencoded URI, such as http://authority@www.ExampleOnly.com/my path/my filename.ext?width=100%&my key=my value#fragment-id
. It is most useful when the entire URI is hard-coded in the JavaScript code, so that escaping of special characters within any component is already done manually.
- encodes all characters that should never be included in a valid URI
- also encodes any percent signs, which is used to encode the unsafe characters
- leaves intact the special characters
#& ./:=?@
that act as delimiters within a URI along with$;
and all other characters not encoded by encodeURIComponent - uses percent escape encoding of individual UTF-8 octets for non-ASCII characters
encodeURIComponent
function can be used to encode individual components of a URI such as http
, authority
, www.ExampleOnly.com
, my path
, my filename.ext
, width
, 100%
, my key
, my value
and fragment-id
from the example used for encodeURI above. This is the function that should be used when the URI is being constructed from variables containing individual components of the URI.
- encodes the special characters
#$& ,/:;=?@
within a component, in addition to those encoded by the encodeURI function, so they won't be misinterpreted as URI delimiters - leaves intact the alphanumeric characters and special characters
!'()*-._~
, which are considered "safe" by RFC 1738, but does encode the characters$ ,
anyway - uses percent escape encoding of individual UTF-8 octets for non-ASCII characters
- The JavaScript escape function should be avoided but may be seen in older code that encodes a space as a plus sign (
+
) or that was designed to be compatible with older browsers - should not be used for text that may contain non-ASCII characters because Unicode characters are converted into a non-standard format as
%unnnn
rather than using UTF-8 percent escape codes
JavaScript percent-encoding functions
In all cases, the resulting URI still needs to be converted to valid HTML, by encoding quotes within attributes, ampersands, etc. using HTML character codes.
(space) | %20 | %20 | %20 | %20 |
! | ! | ! | ! | %21 |
" | %22 | %22 | %22 | %22 |
# | # | # | %23 | %23 |
$ | $ | $ | %24 | %24 |
% | %25 | %25 | %25 | %25 |
& | & | & | %26 | %26 |
' | ' | ' | ' | %27 |
( | ( | ( | ( | %28 |
) | ) | ) | ) | %29 |
* | * | * | * | * |
(space) | %20 | %20 | %20 | %20 |
, | , | , | %2C | %2C |
- | - | - | - | - |
. | . | . | . | . |
/ | / | / | %2F | / |
: | : | : | %3A | %3A |
; | ; | ; | %3B | %3B |
< | %3C | %3C | %3C | %3C |
= | = | = | %3D | %3D |
> | %3E | %3E | %3E | %3E |
? | ? | ? | %3F | %3F |
@ | @ | @ | %40 | @ |
[ | %5B | %5B | %5B | %5B |
\ | %5C | %5C | %5C | %5C |
] | %5D | %5D | %5D | %5D |
^ | %5E | %5E | %5E | %5E |
_ | _ | _ | _ | _ |
` | %60 | %60 | %60 | %60 |
{ | %7B | %7B | %7B | %7B |
| | %7C | %7C | %7C | %7C |
} | %7D | %7D | %7D | %7D |
~ | ~ | ~ | ~ | %7E |
© | %C2%A9 | %C2%A9 | %C2%A9 | %A9 |
® | %C2%AE | %C2%AE | %C2%AE | %AE |
— | %E2%80%94 | %E2%80%94 | %E2%80%94 | %u2014 |
™ | %E2%84%A2 | %E2%84%A2 | %E2%84%A2 | %u2122 |
相关推荐
`encode` 和 `escape` 是处理字符串时经常遇到的两个概念,尤其在处理字符编码和网络传输时更为关键。在这篇博文中,我们将深入探讨这两个概念,以及它们在Java中的具体实现。 首先,让我们了解`encode`。字符串`...
Video Encode and Decode GPU Support Matrix.xlsx
HDB3 ENCODE AND DECODE,详细设计与实现,参考一下下啊
DVI 1.0 encode and decode source code, write with verilog, with simulation project, synplify project and all soure code. They're have been running on xilinx spartan3A FPGA. Can be used in real project...
Turbo编码和解码是无线通信领域中的关键技术,特别是在LTE(Long Term Evolution)系统中,它对数据传输的高效性和可靠性起着至关重要的作用。本文将深入探讨Turbo编码的工作原理、编码过程、解码策略以及在LTE系统...
using labview to encode DTMF tone and play through sound card and record DTMF tone from sound card and decode.
`base64_encode`和`urlencode`是两种常见的编码方法,分别用于不同的场景。 `base64_encode`是一种基于64个可打印字符来表示二进制数据的编码方式。它的基本原理是将每3个字节的数据转换为4个6位的字符,这样可以...
JavaScript中的`encode`和`decode`是一组用于字符串编码解码的方法,它们在处理和传输数据时起到关键作用。在JavaScript中,常见的编码方法有`encodeURIComponent`、`decodeURIComponent`、`encodeURI`、`decodeURI`...
"jQuery JSON with PHP json_encode and json_decode"这个主题涉及到如何利用JSON(JavaScript Object Notation)这一轻量级的数据交换格式,结合PHP的`json_encode`和`json_decode`函数,实现前后端之间的数据通信...
在IT领域,JPEG(Joint Photographic Experts Group)是一种广泛使用的有损图像压缩标准,它能够有效地减少图像文件的大小,适合于在网络上传输和存储。本文将深入探讨JPEG编码解码过程,以及如何使用C/C++语言实现...
"encode and decode"的主题涵盖了这个关键领域。在提供的标签中提到了"open - RSA",这指的是OpenSSL库中的RSA加密算法,这是一种广泛使用的公钥加密技术。 RSA(Rivest-Shamir-Adleman)是一种非对称加密算法,由...
### HtmlEncode与HtmlDecode编码及解码用法详解 #### 一、HtmlEncode与HtmlDecode概念解析 在Web开发中,经常会遇到需要处理HTML代码的情况。为了确保网页内容的正确显示以及防止潜在的安全威胁(如XSS攻击),...
JavaScript中的`encode64`加密算法是一种用于对数据进行编码的方法,它将二进制数据转化为可以在URL、电子邮件等环境中安全传输的文本格式。在JavaScript中实现`encode64`通常涉及将字节序列转换为Base64字符,Base...
用JavaScript实现PHP里的Base64编码与解码。 使用方法: encode64('要编码的字符串'); decode64('要解码的字符串');
VB Script EnCode是一种在VBScript(Visual Basic Script)编程环境中使用的加密技术,它允许程序员对源代码进行编码,以防止未经授权的用户查看或修改代码。VBScript是Microsoft开发的一种脚本语言,常用于Web页面...
《深入理解encode加密解密技术》 在信息技术领域,数据安全是至关重要的议题,而加密技术则是保护数据安全的重要手段。本文将详细探讨encode加密解密的概念、原理以及实际应用,旨在帮助读者全面理解这一技术。 一...
字符串转EnCode_c# 字符串转EnCode_c# 字符串转EnCode_c# 字符串转EnCode_c# 字符串转EnCode_c# 字符串转EnCode_c# 字符串转EnCode_c# 字符串转EnCode_c#
标题中的“jpeg-encode.zip_jpeg_jpeg encode_jpeg encode linux_linux视频监控_视频监”表明这个压缩包可能包含了一组用于在Linux环境下进行JPEG编码的工具或代码库,特别适用于资源有限的嵌入式系统,例如视频监控...
在易语言中进行encode加密解密是一项重要的安全技术应用,它涉及到数据的保护和隐私的安全。 易语言encode加密是将原始数据转换为无法轻易识别的密文过程,目的是为了防止未经授权的访问或篡改。常见的加密算法有...