PHP urlencode空格js解码后变成+号的解决办法

PHP与SEO 思享 977浏览

在某个函数中,为了避免字符串空格对命令行的影响,所以打算把字符串使用urlencode进行编码,然后在js中用decodeURI()进行解码。结果出处过程中发现空格变成了+号,而?号变成了%的字符串

解决办法

PHP使用rawurlencode()来进行编码即可~此函数遵循RFC 3986标准,空格会被转为%20同时,对于此函数转码的url,普通的urldecode是不能正确解码的,所以官方也提供了rawurldecode()函数来对转码后的结果解码再者,你也不需要担心版本兼容问题,因为它在PHP4就已经支持了~

以上来源于《PHP urlencode空格被转为+的问题

至于?号的问题,使用decodeURIComponent()进行解码

推荐阅读

Function get_magic_quotes_gpc() is deprecated报错解决办法

在 PHP 7.4 及更高版本中, get_magic_quotes_gpc() 函数已被弃用。 This means that code using this function will raise a warning or error.以下是解决......

PHP提示:Warning: count():Parameter must be an array or an object that implements Countable

错误原因:PHP7.2以后,count()函数的参数无效时会抛出warning警告。...

PHP7.4 报错:Deprecated Functionality: implode(): Passing glue string after array is deprecated.

PHP7.4运行项目报错:Deprecated Functionality: implode(): Passing glue string after array is deprecated。只需交换 implode() 函数的两个参数!...