當前位置:首頁 » 編程語言 » phpisutf8

phpisutf8

發布時間: 2023-03-01 03:29:05

php如何判斷文件編碼格式的

<?php
$str="白";
/***
也可以從文件讀取內容
$filename = "a.txt";
$handle = fopen($filename, "r");
$str = fread($handle, filesize ($filename));
fclose($handle);
*/
$encode = mb_detect_encoding($str, array("ASCII",'UTF-8','GB2312',"GBK",'BIG5'));
if($encode=="UTF-8"){
echo "is:UTF-8";
}else{
echo "not:UTF-8";
}
?>

㈡ 在PHP中,匹配中文utf8的正則表達式

$str = "編程";
// if(!preg_match("/^[\x{4e00}-\x{9fa5}A-Za-z0-9_]+$/u",$str)) //UTF-8漢字字母數字下劃線正則表達式
if(!preg_match("/^[\x{4e00}-\x{9fa5}]+$/u",$str)) //UTF-8漢字字母數字下劃線正則表達式
{
echo "<font color=red>您輸入的[".$str."]含有違法字元</font>";
}
else
{
echo "<font color=green>您輸入的[".$str."]完全合法,通過!</font>";

}

㈢ 如何把php文件編碼更改為utf-8

與 php 編碼有關的,有兩處地方:


1、php 文件本身的編碼格式:

根據使用 php 編寫軟體的不同,其操作方法有所區別,比如 phpDesigher 軟體:


<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>

㈣ PHP完美判斷字元串是否為utf

完美判斷函數:
function is_utf8($gonten){if (preg_match(/^([.chr(228).-.chr(233).]{1}[.chr(128).-.chr(191).]{1}[.chr(128).-.chr(191).]{1}){1}/,$word) == true || preg_match(/([.chr(228).-.chr(233).]{1}[.chr(128).-.chr(191).]{1}[.chr(128).-.chr(191).]{1}){1}$/,$word) == true || preg_match(/([.chr(228).-.chr(233).]{1}[.chr(128).-.chr(191).]{1}[.chr(128).-.chr(191).]{1}){2,}/,$word) == true){return true;}else{return false;}}使用方法 is_utf8($gonten)就可以判斷字元串$gonten是否為utf-8編碼了。
網上流傳著這樣一個判斷函數,其實這函數判斷是不完整的,函數如下
function is_utf8($string) {
return preg_match('%^(?:
[\x09\x0A\x0D\x20-\x7E] # ASCII
| [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
| \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
| [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
| \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
| \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
| [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15

㈤ 如何用php設置utf-8編碼

在你的源文件找到<meta http-equiv="content-type" content="text/html;charset=utf-8">charset= 後面接的就是編碼,你全部改了就可以了。如果你改了之後變成亂碼的話,那你就只能先建一個utf-8編碼的網頁,把相應的內容重新輸入進去。

㈥ PHP mb_convert_encoding 獲取字元串編碼類型實現代碼

後來又在手冊上找到了is_utf8函數,這樣,再結合iconv函數,我的問題就解決了。下面帖出這個函數:
復制代碼
代碼如下:
function
is_utf8($string)
{
return
preg_match('%^(?:
[\x09\x0A\x0D\x20-\x7E]
#
ASCII
|
[\xC2-\xDF][\x80-\xBF]
#
non-overlong
2-byte
|
\xE0[\xA0-\xBF][\x80-\xBF]
#
excluding
overlongs
|
[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}
#
straight
3-byte
|
\xED[\x80-\x9F][\x80-\xBF]
#
excluding
surrogates
|
\xF0[\x90-\xBF][\x80-\xBF]{2}
#
planes
1-3
|
[\xF1-\xF3][\x80-\xBF]{3}
#
planes
4-15
|
\xF4[\x80-\x8F][\x80-\xBF]{2}
#
plane
16
)*$%xs',
$string);
}
//
function
is_utf8
如果想深入研究,建議看下PHP手冊上的「Multibyte
String
Functions」這一部分的內容。

熱點內容
linuxsnmp安裝 發布:2025-07-02 23:07:08 瀏覽:649
北理c語言答案 發布:2025-07-02 23:05:57 瀏覽:304
sql同比 發布:2025-07-02 23:03:39 瀏覽:835
一個伺服器獲取多個ip 發布:2025-07-02 23:02:43 瀏覽:786
三星電腦wifi怎麼連接wifi密碼 發布:2025-07-02 22:55:00 瀏覽:712
安卓開發選哪個版本的SDK 發布:2025-07-02 22:19:07 瀏覽:486
未上傳圖片 發布:2025-07-02 22:14:01 瀏覽:599
安卓qq直播怎麼分享聲音 發布:2025-07-02 22:13:21 瀏覽:250
安卓系統怎麼刷機清除內存 發布:2025-07-02 22:08:19 瀏覽:697
安卓手機6位數密碼有多少組 發布:2025-07-02 21:50:31 瀏覽:798