Get Chinese Initials program code _php Tutorial in PHP

Source: Internet
Author: User
We often see a number of sites by city name or alphabetical ranking, I would like to introduce how this thing to achieve it, we share a section of the use of PHP to obtain the Chinese characters in the first character of the letter.
The code is as follows Copy Code

Cases

!--? php
$limit = Array (//gb2312 phonetic sort
Array (45217,45252),//a
Array (45253,45760),//b
Array (45761 , 46317),//c
Array (46318,46825),//d
Array (46826,47009),//e
Array (47010,47296),//f
Array (47297,47613 ),//g
Array (47614,48118),//h
Array (0,0),//i
Array (48119,49061),//j
Array (49062,49323),//k
Array (49324,49895),//l
Array (49896,50370),//m
Array (50371,50613),//n
Array (50614,50621),//o
Array ( 50622,50905),//p
Array (50906,51386),//q
Array (51387,51445),//r
Array (51446,52217),//s
Array ( 52218,52697),//t
Array (0,0),//u
Array (0,0),//v
Array (52698,52979),//w
Array (52980,53688),//x
Array (53689,54480),//y
Array (54481,55289),//z
);

$str = "A: This is a test program 1";
$str = Iconv ("UTF-8", "gb2312", $str);
echo $str. "
";
$i = 0;
while ($i
$tmp =bin2hex (substr ($str, $i, 1));
if ($tmp >= ' B0 ') {//start of Kanji
$t =getletter (Hexdec (Bin2Hex (substr ($str, $i, 2)));
printf ("%c", $t ==-1? ' * ': $t);
$i +=2;
}
else{
printf ("%s", substr ($str, $i, 1));
$i + +;
}
}

function Getletter ($num) {
Global $limit;
$char _index=65;
foreach ($limit as $k = = $v) {
if ($num >= $v [0] && $num <= $v [1]) {
$char _index+= $k;
return $char _index;
}
}
return-1;
}
?>

It is based on Chinese pinyin to determine its ASCII code to calculate the OH.


http://www.bkjia.com/PHPjc/444630.html www.bkjia.com true http://www.bkjia.com/PHPjc/444630.html techarticle we often see a number of sites by city name to rank or alphabetically ranked, below I would like to introduce how this thing to achieve it, we share a section using PHP to get the Chinese string ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.