PHP 跟 Javascript 都有 HTML encoding 的函式,編碼過的結果雖然類似,但是還是有些微的不同,所以不能互轉。
二者的差異可以可參考:
http://web.archive.org/web/20030811181238/http://php.weblogs.com/php_jscript_vbscript_1
節錄如下:
PHP:
urlencode( ) All punctuation, accented characters, and any other non-ASCII characters are replaced with %xx encoding. Spaces converted to +.
urldecode( )All punctuation, accented characters, and any other non-ASCII characters are replaced with %xx encoding. Spaces converted to +.
Javascript::
escape(str) All spaces, punctuation, accented characters, and any other non-ASCII characters are replaced with %xx encoding
那要如何用 PHP 來讀取 escape() 編碼過的字串呢?可以用以下的方式來讀取 (範例為 Unicode 解譯為 big5)
修改自:http://web.archive.org/web/20041031225806/http://vivian.stripper.jp/index.php?itemid=100
$str = uniDecode($str,'big-5');
function uniDecode($str,$charcode){
$text = preg_replace_callback("/%u[0-9A-Za-z]{4}/",toUtf8,$str);
return mb_convert_encoding($text, $charcode, 'utf-8');
}
function toUtf8($ar){
foreach($ar as $val){
$val = intval(substr($val,2),16);
if($val < 0x7F){ // 0000-007F
$c .= chr($val);
}elseif($val < 0x800) { // 0080-0800
$c .= chr(0xC0
($val / 64));
$c .= chr(0x80
($val % 64));
}else{ // 0800-FFFF
$c .= chr(0xE0
(($val / 64) / 64));
$c .= chr(0x80
(($val / 64) % 64));
$c .= chr(0x80
($val % 64));
}
}
return $c;
}
參考資料:http://www.neo.com.tw/archives/152
訂閱:
張貼留言 (Atom)
聖誕跑趴歡樂降★韓版假兩件針織連衣裙$890,新款顯瘦棒球服連帽風衣外套下殺$510,冬新款歐美棉襖棉服連帽短款外套限量↘$530,秋冬新款韓版大碼毛領氣質毛料外套↘$680,快上左耳貓網路購物
您好!如圖太小看不清楚,請 點選此處 看詳細內容 左耳貓蝦皮賣場 https://shopee.tw/hrf5168 左耳貓 露天賣場 http://class.ruten.com.tw/user/index00.php?s=starbox 左耳貓粉...


-
很多朋友在利用phpmailer透過gmail發送mail時,常發生無法寄送的錯誤,而其中最常見的就是php沒有支援openssl的關係,有鑑於此YOGO特別寫了這篇就學,希望能對這方面有困擾的朋友能有所幫助,至於phpmailer的設定方式,就請參考YOGO寫的另一篇文章(&...
-
YOGO整理了一下,用PHP來發MAIL的方法給有需要的朋友參考一下 1.用PHP內建的mail()函式 一般在發信時入須要先設好您的mail-server,會有問題的大多是windows的系統.在使用這一個函式時如果出現找不到函式那就是您的mail-s...
-
今天在Yahoo知識+看到一則討論,是關於php如何十進位轉二進位的問題( http://tw.knowledge.yahoo.com/question/question?qid=1609073000065 ),在該討論中原提問者希望最終結果可以以1~255的十進...

沒有留言:
張貼留言