預覽的部分,我們作了一些 trick
當編碼是 UTF-8時
我們是用 encodeURIComponent 來作 url encode
當其他編碼時
我們用 escape 來作 urlencode
我在猜可能 big5/gb2312 也都得用 encodeURIComponent 來作 url encode
你可以看一下 /js/plogui/common.js 下的 getPostEditFormElements,把 GB2312 與 big5 的判斷加入試試看。
Mark
hi mark:
忽然想起來,曾看過的這個:
urlencode
(PHP 3, PHP 4 , PHP 5)
urlencode -- URL-encodes string
Description
string urlencode ( string str )
Returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs. It is encoded the same way that the posted data from a WWW form is encoded, that is the same way as in application/x-www-form-urlencoded media type.
※來自
http://www.php.net/manual/en/function.urlencode.php和這個:
Returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits. This is the encoding described in RFC 1738 for protecting literal characters from being interpreted as special URL delimiters, and for protecting URL's from being mangled by transmission media with character conversions (like some email systems). For example, if you want to include a password in an FTP URL:
Or, if you pass information in a PATH_INFO component of the URL:
※來自
http://www.php.net/manual/en/function.rawurlencode.php所以,我的認知是,用在 URL 後面的 Query 字串應該用 urlencode ;而用在 path_info (網址的一部份)的則是用 rawurlencode 。
相對於 JavaScript ,要用 encodeURIComponent 或 escape 應該是由字串在 path_info 還是 query string 來決定,而跟那一種語系編碼無關。
不知道有沒有錯,大家討論一下。