ホームページ  >  記事  >  バックエンド開発  >  PHP判断字符串编码是不是为utf8的函数

PHP判断字符串编码是不是为utf8的函数

WBOY
WBOYオリジナル
2016-06-13 10:38:28783ブラウズ

PHP判断字符串编码是否为utf8的函数
http://it.oyksoft.com/post/49/

// Returns true if $string is valid UTF-8 and false otherwise.function is_utf8($word){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;}} // function is_utf8

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。