PHP 中 JavaScript 的 encodeURI 组件的等价物是什么? [英] What is the equivalent of JavaScript's encodeURIcomponent in PHP?

查看:23
本文介绍了PHP 中 JavaScript 的 encodeURI 组件的等价物是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JavaScript 的 encodeURIcomponent 函数在 PHP 中的等价物是什么?

What is the equivalent of JavaScript's encodeURIcomponent function in PHP?

推荐答案

Try rawurlencode.或者更准确地说:

Try rawurlencode. Or to be more precise:

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

此功能完全正常如何encodeURIComponent 已定义:

This function works exactly how encodeURIComponent is defined:

encodeURIComponent 转义除以下字符之外的所有字符:字母、十进制数字、- _ . ! ~ * ' ( )

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

这篇关于PHP 中 JavaScript 的 encodeURI 组件的等价物是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆