本文目錄一覽:
用phpstr_replace() 如何替換utf8頁面的中文,調用的頁面是UTF8?
首先保證str_replace時編碼程序與調用的頁面代碼一致,比如程序文件的編碼為UTF8,調用頁面的編碼也是UTF8,這樣在程序代碼中就可以直接使用中文了。
str_replace(‘哈哈’,’呵呵’,$buffer)
怎樣將php源程序改為utf8
給個轉碼的方法給你吧! 你可以自己修改$outEncoding的參數,下面的方法默認是轉換為gb2312的字符集了,你調用方法就可以將你的字元串轉換字元
//中文字元編碼轉換
public function safeEncoding($string,$outEncoding =’GB2312′)
{
$encoding = “UTF-8”;
for($i=0;$istrlen($string);$i++)
{
if(ord($string{$i})128)
continue;
if((ord($string{$i})224)==224)
{
//第一個位元組判斷通過
$char = $string{++$i};
if((ord($char)128)==128)
{
//第二個位元組判斷通過
$char = $string{++$i};
if((ord($char)128)==128)
{
$encoding = “UTF-8”;
break;
}
}
}
if((ord($string{$i})192)==192)
{
//第一個位元組判斷通過
$char = $string{++$i};
if((ord($char)128)==128)
{
// 第二個位元組判斷通過
$encoding = “GB2312”;
break;
}
}
}
if(strtoupper($encoding) == strtoupper($outEncoding))
return $string;
else
return iconv($encoding,$outEncoding,$string);
}
如何把php文件編碼更改為utf-8
與 php 編碼有關的,有兩處地方:
1、php 文件本身的編碼格式:
根據使用 php 編寫軟體的不同,其操作方法有所區別,比如 phpDesigher 軟體:
2、php 文件內容里,需要設置供瀏覽器進行解析時需要的編碼格式:
在 PHP 文件代碼里,插入
header(“Content-type: text/html; charset=utf-8”);
相當於 html 的
meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ /
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/287245.html