php - PHP 中 JavaScript 的 encodeURIcomponent 等价物是什么

PHP中JavaScript的encodeURIcomponent函数等价于什么?

最佳答案

试试 rawurlencode .或者更准确地说:

function encodeURIComponent($str) {
    $revert = array('%21'=>'!', '%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')');
    return strtr(rawurlencode($str), $revert);
}

此功能完全有效how encodeURIComponent is defined :

encodeURIComponent escapes all characters except the following: alphabetic, decimal digits, - _ . ! ~ * ' ( )

关于php - PHP 中 JavaScript 的 encodeURIcomponent 等价物是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1734250/

相关文章:

php - 如何使用 PHP 检查远程文件是否存在?

php - 防止 Laravel 向数据透视表添加多条记录

php - 将秒转换为天、小时、分钟和秒

php - 解释 $CI =& get_instance();

php - GD vs ImageMagick vs Gmagick for jpg?

php - 如何在函数调用中跳过可选参数?

php - Apache 正在下载 php 文件而不是显示它们

php - 生成随机 5 个字符的字符串

php - 日期减去 1 年?

php - Ubuntu 在终端输入 'php' 显示很多错误