在网址中编码特殊字符的最佳方法 [英] Best way to encode special chars in url
本文介绍了在网址中编码特殊字符的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在URL中编码特殊字符的最佳方法是什么?假设我以这种方式将变量从javascript传递到php脚本:
What is the best way to encode special characters in a url? Let's say I pass an variable from javascript to a php script that way:
http://example.com/my sp3c!al var!a$le
编码特殊字符(如空格,!)的最佳方法是什么? ,$,/,\等)?
What is the best way to encode that special characters (like whitespace, !, $, /, \ etc.)? Is there a method in javascript to encode it with a corresponding function in php to decode it there?
推荐答案
您需要利用javascript中的一种方法,用php中的相应功能对其进行编码吗?的 encodeURIComponent(yourvar);
You need to make use of encodeURIComponent(yourvar);
这篇关于在网址中编码特殊字符的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文