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; 网友回复
WinUI3和Electron有啥不同?
有哪些版权中心可以合作发布短剧漫剧进行赚钱?
ai装修解压视频提示词如何写?
有哪些视频钩子可以解决5s完播低问题?
seedance2如何根据一张九宫格分镜头图片生成ai视频短剧?
www.gstatic.com打开报错net::ERR_TUNNEL_CONNECTION_FAILED
果蝇大脑神经在计算机中复原意味人脑神经和意识也可在计算机中复原?
cosyvoice-v3.5声音克隆报错:Error during speech synthesis: start speech synthesizer failed within 5s.
html如何实现二进制程序转成汇编代码?
python如何通过音色描述和说话内容生成语音?


