1. 程式人生 > >js和php的url編碼

js和php的url編碼

寫一個urlcode.html的檔案

如下

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<script type="text/javascript">
    var url2="urldecode.php?a=1&b="+encodeURIComponent("2&3");
    window.location.href=url2;
    
</script>

</body>
</html>

 

 

再寫一個urldecode.php的檔案

<?php


echo 'a:'.$_GET['a'];

echo 'b:'.urldecode($_GET['b']);

?>

 

 

發現列印

a:1b:2&3

說明b解碼成功