[英]URL encoding with Javascript and then decoding with PHP
我想用Javascript對字符串進行url編碼,其中代碼的相關部分是:
this.options[this.selectedIndex].value
或整行:
<select name="category" onChange="javascript:document.location.href='<? echo '/' . $state . '/dir/'; ?>' + this.options[this.selectedIndex].value;">
如何使用JS對URL進行編碼,然后使用urldecode
使用PHP安全地對其進行解碼?
我想在URL中使用&時遇到問題。 我只是使用encodeURIComponent()
解決了它。
我在下拉元素的onchange函數中使用了它,如下所示:
onchange="window.location='test.php?c='+encodeURIComponent(this.value)"
就我而言,它運作良好。
我試圖為此使用php函數urlencode()
,但我做不到。
您有3種選擇:
escape()
將不會編碼: @*/+
encodeURI()
將不會編碼: ~!@#$&*()=:/,;?+'
encodeURIComponent()
不會編碼: ~!*()'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.