PHP Get string First letter method, PHP get string _php Tutorial

Source: Internet
Author: User

PHP gets the string first letter method, PHP gets the string


This example describes how PHP obtains the first letter of a string. Share to everyone for your reference. The implementation method is as follows:

<?php$limit = Array (//gb2312 phonetic sort Array (45217,45252),//a Array (45253,45760),//b Array (45761,46317),//c Array (46 318,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 arr Ay (51446,52217),//s Array (52218,52697),//t Array (0,0),//u Array (0,0),//v Array (52698,52979),//w Array (52 980,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 = ' B0 ') {//The beginning of the 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;}? >

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/973285.html www.bkjia.com true http://www.bkjia.com/PHPjc/973285.html techarticle PHP gets the string initials method, PHP Gets the string This example describes how PHP obtains the first letter of the string. Share to everyone for your reference. The concrete implementation method is as follows: P ...

  • 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.