iT邦幫忙

0

想請問一下, 『\xe5\xbc\xb5\xe4\xbb\x81\xe5\xa8\x81.tw』是啥東東?

afgn 2012-05-01 13:47:136124 瀏覽

想請問一下, 『\xe5\xbc\xb5\xe4\xbb\x81\xe5\xa8\x81.tw』是啥東東? 這是我在執行 apachectl restart 時出現的錯誤訊息... 我知道這是中文網址的亂碼, 但是不知道怎麼出現的 >"<

我的Linux 語系是 en_us.UTF-8 (@/etc/sysconfig/i18n), 而 putty 的Remote character set也是 utf-8, 且 /usr/local/apache/conf/httpd.conf 檔案的編碼也是 utf-8, 要怎樣可以讓它正常的顯示中文? 在Command line有沒有什麼指令可以讓它顯示正確的中文字? 或是利用PHP的哪個函數 (例如 utf8_decode), 或是直接修改 httpd.conf 讓它可以正常顯示中文錯誤訊息? 謝謝囉!!

看更多先前的討論...收起先前的討論...
這個不叫亂碼
而是經過編碼後的特殊字元
wiseguy iT邦超人 1 級 ‧ 2012-05-14 11:33:19 檢舉
呵 ... 我們 RD 都很清楚它是什麼,但以外的人,凡肉眼無法辨識解譯者,皆以亂碼稱呼之。偷笑
wiseguy提到:
亂碼


XD
還是來回味一下亂馬 1/2 好了
afgn iT邦新手 5 級 ‧ 2012-05-18 15:28:26 檢舉
那有名字嗎?? 像是 Puny Code, UTF-8, Unicode, Base64, HTML 16進位.... :P
有興趣知道的話請到下列網址餵關鍵字:http

http://www.rfc-editor.org/cgi-bin/rfcsearch.pl
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
26
wiseguy
iT邦超人 1 級 ‧ 2012-05-01 20:42:42
最佳解答

apache 的 Log 會自動把 ACSII 127 之後的字元編碼轉成你所看到以 \x 來表示的 16 進位碼。你可以用下列 php 程式兩種方式看到原來的字:

&lt;pre class="c" name="code"><?php
// 第一種方法全字串都必須是 \xHH 才行
echo iconv('UTF-8', 'Big5', pack('H*', str_replace('\x', '', '\xe5\xbc\xb5\xe4\xbb\x81\xe5\xa8\x81'))), "\n";
// 第二種方法可以含有不是 \xHH 的字
echo iconv('UTF-8', 'Big5', preg_replace('/\\\x([[:xdigit:]]{2})/e', 'pack("H*", "\1")', '\xe5\xbc\xb5\xe4\xbb\x81\xe5\xa8\x81.tw')), "\n";
?>
4
bzbz
iT邦新手 2 級 ‧ 2012-05-01 17:49:25

張仁威.tw

6
joanchen
iT邦新手 5 級 ‧ 2012-05-03 13:25:59

我記得是 httpd.conf 要修改

AddDefaultCharset UTF-8 拿掉 .或者mark 起來 (最好是 mark)
讓 client 的 系統自動編碼. 應該就 OK

wiseguy iT邦超人 1 級 ‧ 2012-05-03 14:40:43 檢舉

引自官方文件 http://httpd.apache.org/docs/2.2/mod/mod_log_config.html

For security reasons, starting with version 2.0.46, non-printable and other special characters in %r, %i and %o are escaped using \xhh sequences, where hh stands for the hexadecimal representation of the raw byte. Exceptions from this rule are " and \, which are escaped by prepending a backslash, and all whitespace characters, which are written in their C-style notation (\n, \t, etc). In versions prior to 2.0.46, no escaping was performed on these strings so you had to be quite careful when dealing with raw log files.

Apache 2.0.46 版以後,基於安全問題,不可印與某些特別字元,都會用 \xHH 跳脫。所以除非使用 2.0.46 以前的版本,Log 中才有可能看到原始 URL。

我要發表回答

立即登入回答