/xiaolei.php|martin_十步解决Php Utf-8编码(转贴)
php用UTF-8總結:
1、php文件本身必須是UTF-8編碼。不像Java會生成class文件,避免這個問題
2、php要輸出頭:header(”Content-Type: text/html; charset=UTF-8″)
3、meta標簽無所謂,有header所有瀏覽器就會按header來解析
4、所有外圍都得用UTF8,包括數(shù)據(jù)庫、*.js、*.css(CSS影響倒不大)
5、php本身不是Unicode的,所有substr之類的函數(shù)得改成mb_substr(需要裝mbstring擴展);或者用iconv轉碼(基本上的linux都裝了,沒裝的話download、tar、make、make install,很簡單的)
6、my.ini:
[mysql]
default-character-set=utf8
[mysqld]
default-character-set=utf8
default-storage-engine=MyISAM
在[mysqld]下加入:
default-collation=utf8_bin
init_connect='SET NAMES utf8'
7、在需要做數(shù)據(jù)庫操作的php程序前面加上
mb_internal_encoding('utf-8');
8、create table最后邊加上ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin
9、phpMyAdmin/config.inc.php
$cfg['DefaultCharset'] = 'utf-8';
$cfg['RecodingEngine'] = 'iconv';
10、phpAdmin導出數(shù)據(jù)時
把"二進制區(qū)域使用十六進制顯示"的勾去掉
特別郁悶的:文件系統(tǒng)函數(shù)不支持UTF-8!
聽說php6已經(jīng)內置Unicode支持,以后試一下
來源:http://www.ruanyifeng.com/notes/2007/10/php_utf8.html
總結
以上是生活随笔為你收集整理的/xiaolei.php|martin_十步解决Php Utf-8编码(转贴)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 求解素来悬赏
- 下一篇: 数据库_数据库篇-第一章:数据库基本概念