定義
urlencode - 將傳入的字串進行URL編碼
描述
urlencode ( string $str ) : string
其回傳的字串中除了 —_. 和數字字母外,所有其他字符 non-alphanumeric 都被替換成百分號(%)后跟兩位十六進制數,空格則編碼為加號(+),
此編碼與 WWW 表單 POST 資料的編碼方式是一樣的,同時與 application/x-www-form-urlencoded 的媒體型別編碼方式一樣,
此函式便于將字串編碼并將其用于URL的請求引數,同時還便于將變數編碼后傳遞給下一頁,
urlencode是指標對網頁url中的中文字符的一種編碼轉化方式,一般有兩種,分別基于GB2312和UTF-8,如下
中文 -> GB2312的Encode -> %D6%D0%CE%C4
中文 -> UTF-8的Encode -> %E4%B8%AD%E6%96%87
示例
//GB2312的Encode
echo urlencode("中文-_. ")."\n"; //%D6%D0%CE%C4-_.+
echo urldecode("%D6%D0%CE%C4-_. ")."\n"; //中文-_.
echo rawurlencode("中文-_. ")."\n"; //%D6%D0%CE%C4-_.%20
echo rawurldecode("%D6%D0%CE%C4-_. ")."\n"; //中文-_.
urlencode和rawurlencode的區別
urlencode 將空格則編碼為加號(+)
rawurlencode 將空格則編碼為加號(%20)
urldecode
urldecode - 解碼已編碼的 URL 字串
urldecode ( string $str ) : string
urldecode()函式與urlencode()函式原理相反,用于解碼已編碼的 URL 字串,其原理就是把十六進制字串轉換為中文字符,
Decodes any %## encoding in the given string.
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/53129.html
標籤:PHP
