Heim > php教程 > php手册 > Hauptteil

php 中文字符串首字母的获取函数分享

WBOY
Freigeben: 2016-06-13 09:31:16
Original
803 Leute haben es durchsucht

复制代码 代码如下:


function chineseFirst($str)
{

    $str= iconv("UTF-8","gb2312", $str);    //如果程序是gbk的,此行就要注释掉

    //判断字符串是否全都是中文
    if (preg_match("/^[\x7f-\xff]/", $str))
    {
        $fchar=ord($str{0});  
        if($fchar>=ord("A") and $fchar        $a = $str;
        $val=ord($a{0})*256+ord($a{1})-65536;
        if($val>=-20319 and $val        if($val>=-20283 and $val        if($val>=-19775 and $val        if($val>=-19218 and $val        if($val>=-18710 and $val        if($val>=-18526 and $val        if($val>=-18239 and $val        if($val>=-17922 and $val        if($val>=-17417 and $val        if($val>=-16474 and $val        if($val>=-16212 and $val        if($val>=-15640 and $val        if($val>=-15165 and $val        if($val>=-14922 and $val        if($val>=-14914 and $val        if($val>=-14630 and $val        if($val>=-14149 and $val        if($val>=-14090 and $val        if($val>=-13318 and $val        if($val>=-12838 and $val        if($val>=-12556 and $val        if($val>=-11847 and $val        if($val>=-11055 and $val    } else
    {
        return false;
    }

}

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!