2011年1月22日 星期六

網頁編碼



















apache
AddDefaultCharset UTF-8
html
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
php:
1.<?php

header('Content-type: text/html; charset=utf-8');

?>
2.<?php

$new_str = iconv("BIG5", "UTF-8", $old_str);  //big5轉utf8

$new_str = iconv("UTF-8", "BIG5", $old_str); //utf85轉big5

?>
3.<?php

//mysql

mysql_query("SET NAMES 'utf8'");

?>
4.<?php

//sqlsrv(MSSQL)

$connectionInfo = array( "UID"=>"帳號", "PWD"=>"密碼", "Database"=>"資料庫名稱","CharacterSet" => "UTF-8");

?>
5.<?php

//sqlsrv(MSSQL)

while(sqlsrv_fetch($stmt)){

    echo sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STRING("UTF-8"))."</br>";

?>