天天看點

urlencode()與urldecode() 詳解

urlencode()編碼:對字元串中除了 -_. 之外的所有非字母數字字元都将被替換成百分号(%)後跟兩位
​​十六進制數​​​
,空格則編碼為加号(+)。

urldecode()解碼:還原 URL 編碼字元串。

示例:

<?php

header("Content-Type:text/html; charset=utf-8");

//對參數值進行編碼

$parm=urlencode("示範php-mysql");


//拼接url

$url="decode.php?par=".$parm;

?>


<a href="<?php echo $url;?>">urlencode示範</a>


點選連接配接後位址欄中漢字被編碼了: