Home > Backend Development > PHP Tutorial > PHP function sharing for obtaining the first letter of Chinese string_PHP tutorial

PHP function sharing for obtaining the first letter of Chinese string_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:25:35
Original
1161 people have browsed it

Copy code The code is as follows:

function chineseFirst($str)
{

$str= iconv( "UTF-8", "gb2312", $str); // If the program is gbk, this line must be commented out

// Determine whether the strings are all Chinese
if (preg_match( "/^[x7f-xff]/", $str))
{
$fchar=ord($str{0});
if($fchar>=ord("A") and $fchar<=ord("z") )return strtoupper($str{0});
            $a = $str;                 $val=ord($a{0})*256+ord($ a{1})-65536;
if($val>=-20319 and $val<=-20284)return "A";
if($val>=-20283 and $val<=-19776 )return "B";
if($val>=-19775 and $val<=-19219)return "C";
if($val>=-19218 and $val<=-18711)return "D";
if($val>=-18710 and $val<=-18527)return "E";
if($val>=-18526 and $val<=-18240)return "F ";
if($val>=-18239 and $val<=-17923)return "G";
if($val>=-17922 and $val<=-17418)return "H";
if($val>=-17417 and $val<=-16475)return "J";
if($val>=-16474 and $val<=-16213)return "K";       
        if($val>=-16212 and $val<=-15641)return "L";                                 
if ($val>=-15165 and $val<=-14923)return "N"; If($ val>=-14914 and $val<=-14631)return "P"; If($val> =-14149 and $val<=-14091)return "R"; val>=- 13318 and $val<=-12839)return "T"; >=-12556 and $val<=-11848)return "X"; 1055 and $val< ;=-10247)return "Z";
} else
{
return false;
}

}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/824995.htmlTechArticleCopy the code as follows: function chineseFirst($str) { $str= iconv("UTF-8"," gb2312", $str); //If the program is gbk, this line must be commented out //Determine whether the strings are all Chinese...
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template