encodeURIComponent与rawurlencode主要区别在于单引号的处理:
JS的encodeURIComponent保留单引号不编码PHP的rawurlencode会将单引号编码为%27
我们自定义js端的encodeURIComponent:
// 前端使用自定义编码函数
function phpUrlencode(str) {
return encodeURIComponent(str)
.replace(/'/g, '%27') // 单引号转换为%27
.replace(/!/g, '%21')
.replace(/\(/g, '%28')
.replace(/\)/g, '%29')
.replace(/\*/g, '%2A');
}完整的js与php代码一样的对比:<?php
$string="s'f'd双方都()是对方是否";
?>
<script>
const param = phpUrlencode("<?=$string?>");
console.log(param);
// 前端使用自定义编码函数
function phpUrlencode(str) {
return encodeURIComponent(str)
.replace(/'/g, '%27') // 单引号转换为%27
.replace(/!/g, '%21')
.replace(/\(/g, '%28')
.replace(/\)/g, '%29')
.replace(/\*/g, '%2A');
}
</script>
<?php
// PHP代码
$param = rawurlencode($string);
echo $param; 网友回复
ai大模型是不是遇到瓶颈了,现在只优化速度了?
python能写一个检测nginx rewrite高危漏洞的工具代码?
css如何给video视频进行mask遮罩?
windows如何同时允许两个用户远程桌面连接同一个电脑?
nginx升级到1.30.1导致无法启动 [emerg] SSL_CTX_new() failed怎么办?
什么是ASLR(地址随机化)?
有没有不依赖embedding向量的RAG技术?
有没有支持实时打断语音通话并后台帮你执行任何的ai模型?
开源ai大模型文件格式GGUF、MLX、Safetensors、 ONNX 有什么区别?
出海挣钱支付收款PayPal、Wise 、PingPong、Stripe如何选择?


