ホームページ  >  記事  >  バックエンド開発  >  PHP中国語とエンコード判定コード_PHPチュートリアル

PHP中国語とエンコード判定コード_PHPチュートリアル

WBOY
WBOYオリジナル
2016-07-21 15:37:20805ブラウズ

エンコード範囲1. GBK(GB2312/GB18030) -u9fa5 (中国語) x3130-x318F (韓国語) xAC00-xD7A3 (韓国語)
u0800-u4e00 (日本語)

ps: 韓国語は [u9fa5] より大きい文字です

通常の例: preg_replace("/([ x80 -xff])/”,””,$str); preg_replace(”/([u4e00-u9fa5])/”,””,$str);

2. コードをコピーします。

コードは次のとおりです:
//コンテンツに中国語が含まれているかどうかを確認します-GBK (PHP)
function check_is_chinese($s){
return preg_match('/[x80-xff]./', $ s);
}
//文字列の長さを取得する - GBK (PHP) function gb_strlen($str){
$count = 0; $i=0; $i$s = substr($str, $i, 1);

if (preg_match("/[x80-xff]/", $s)) ++$count; return $count; } //インターセプト文字列 string-GBK (PHP) function gb_substr($str, $len){
for($i=0; $iif($count == $len) ブレーク;
if(preg_match("/[x80-xff]/", substr($str, $i, 1)))
++$count ;
}
return substr($str, 0, $i);
//統計文字列長 - UTF8 (PHP)
function utf8_strlen($str) {
$count = 0; $i = 0; $i < $str);
$value = ord($str[$i]);
$count++; $value > ;= 192 && $value <= 223) $i++;
elseif($value >= 224 && $value else die('UTF-8 互換の文字列ではありません');
$count++
}
//インターセプト文字列 -UTF8(PHP)
function utf8_substr($str,$position,$length){
$start_position = strlen($str);
$end_position = strlen($str); = 0 ;
for($i = 0; $i if($count >= $position && $start_position > $i){
$start_position = $i ;
$start_byte = $count;
if(($count-$start_byte)>=$length) {
$end_position = $i;
$value = ord; ]) ;
if($value > 127){
$count++;
if($value >= 192 && $value = 224 && $value < ;= 239) $i = $i + 2;
elseif($value >= 240 && $value else die('UTF-8 互換の文字列ではありません' );
}
$count++;
}
return(substr($str,$start_position,$end_position-$start_position));
}
function checkKoreaChar( str) {
for(i=0; iif(((str.charCodeAt(i) > 0x3130 && str.charCodeAt(i) return true;
}
}
return false
}
//中国語の文字があるかどうかを判断します - GBK (JavaScript) )
function check_chinese_char (s){
return (s.length != s.replace(/[^x00-xff]/g,"**").length);



http://www.bkjia.com/PHPjc/321937.html

www.bkjia.com

本当

http://www.bkjia.com/PHPjc/321937.html

技術記事

コーディング範囲 1. GBK (GB2312/GB18030) x00-xff GBK 2 バイトコーディング範囲 x20-x7f ASCII xa1-xff 中国語 x80-xff 中国語 2. UTF-8 (Unicode) u4e00-u9fa5 (中国語) x3130-x318F (韓国語) ) ...





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