PHP encode/decode 字符串只有数字和字符

PHP encode/decode string only numbers and characters

我知道 PHP 函数 encode() 和 decode(),它们很适合我,但我想在 url 中传递编码字符串,但 encode 确实 return 特殊字符,如“=”、“'”等....

这显然破坏了我的脚本,对字符串进行编码并仅获取数字和字符的最佳方法是什么?

我应该使用特殊的哈希吗?

尝试url编码()

这应该以一种您可以安全地在 url 中传递它的方式对编码字符串进行编码。

还有一种urlencode() and urldecode()尊重特殊字符的方法。

此外,rawurlencode() and rawurldecode() are provided to encode according to RFC-3986。这将 return 一个字符串,其中所有非字母数字字符都已替换为百分号 (%) 后跟两个十六进制数字。