php urlencode和rawurlencode的区别介绍
在php中rawurlencode与rawurlencode都是对字符进行编码的,下面我来给大家介绍urlencode和rawurlencode的区别,有需要了解的朋友可参考。
urlencode的用途就是编码字符串,把原字符串中所有除”-_”以为的非所有字母数字字符替换成百分号(%)后跟两位十六进制数,但是需要注意:由于历史原因会把空格替换+号。rawurlencode其实和urlencode一样,也是用来编码字符串的,唯一的不同是它是使用RFC1738 编码,也就是会把空格替换成%20。
它们对应的解码函数是urldecode和rawurldecode。参考官方网站的说明,urldecode解码给出的已编码字符串中的任何%##,加号(’+')被解码成一个空格字符;rawurldecode解码字符字符串中百分号(%)后跟两位十六进制。有两点区别,一是urldecode解码是对百分号(%)后任意两位字符都去会进行解码,例如%MN也会解码,但是会失败;rawurldecode则只会对百分号(%)后两位是十六进制(0-9A-F)的字符才会解码,二是urldecode会把+号解码为空格。
我们再看来两个函数在php官方的介绍吧。
urlencode — 编码 URL 字符串
Report a bug 说明
string urlencode ( string $str )
此函数便于将字符串编码并将其用于 URL 的请求部分,同时它还便于将变量传递给下一页。
Report a bug 参数
str
要编码的字符串。
Report a bug 返回值
返回字符串,此字符串中除了 -_. 之外的所有非字母数字字符都将被替换成百分号(%)后跟两位十六进制数,空格则编码为加号(+)。此编码与 WWW 表单 POST 数据的编码方式是一样的,同时与 application/x-www-form-urlencoded 的媒体类型编码方式一样。由于历史原因,此编码在将空格编码为加号(+)方面与 RFC1738 编码(参见 rawurlencode())不同。
代码如下 | 复制代码 |
Example #1 urlencode() 例子
echo '';
$query_string = 'foo=' . urlencode($foo) . '&bar=' . urlencode($bar); |
rawurlencode — 按照 RFC 1738 对 URL 进行编码
Report a bug 说明
string rawurlencode ( string $str )
根据 » RFC 3986 编码指定的字符。
Report a bug 参数
str
要编码的 URL。
Report a bug 返回值
返回字符串,此字符串中除了 -_. 之外的所有非字母数字字符都将被替换成百分号(%)后跟两位十六进制数。这是在 » RFC 3986 中描述的编码,是为了保护原义字符以免其被解释为特殊的 URL 定界符,同时保护 URL 格式以免其被传输媒体(像一些邮件系统)使用字符转换时弄乱。
例
代码如下 | 复制代码 |
Example #1 在 FTP URL 里包含一个密码
echo ''; |
通过上面对解码函数的描述,可以推论,使用urlencode或rawurlencode编码的都可以使用urldecode进行解码,但是如果原字符串中含有空格,使用urlencode编码后的字符串使用rawurlencode解码后获得的字符串会和原字符串不同。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

Laravel and ThinkPHP are both popular PHP frameworks and have their own advantages and disadvantages in development. This article will compare the two in depth, highlighting their architecture, features, and performance differences to help developers make informed choices based on their specific project needs.

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.
