首页 > 作文

PHP常用函数之获取汉字首字母功能示例

更新时间:2023-04-08 06:17:09 阅读: 评论:0

本文实例讲述了php常用函数之获取汉字首字母功能。分享给大家供大家参考,具体如下:

//获取汉字的首字母function getfirstcharters($str){  if (empty($str)) {    return '';  }  //取出参数字符串中的首个字符  $temp_str = substr($str,0,1);  if(ord($temp_str) > 127){    $str = substr($str,0,3);  }el{    $str = $temp_str;    $fchar = ord($str{0});    if ($fchar >= ord('a') && $fchar <= ord('z')){      return strtoupper($temp_str);    }el{      return null;    }  }  $s1 = iconv('utf-8', 'gb2312//ignore', $str);  if(empty($s1)){    return null;  }  $s2 = iconv('gb2312', 'utf-8', $s1);  if(empty($s2)){    return null;  }  $s = $s2 == $str ? $s1 : $str;  $asc = ord($s{0}) * 256 + ord($s{1}) - 65536;  if ($asc >= -20319 && $asc <= -20284)    return 'a';  if ($asc >= -20283 && $asc <= -19776)    return 'b';  if ($asc >= -19775 && $asc <= -19219)    return 'c';  if ($asc &英雄联盟adc天赋加点图gt;= -19218 && $asc <= -18711)    return 'd';  if ($asc >= -18710 && $asc <= -18527)    return 'e';  if ($asc >= -18526 && $asc <= -18240)    return 'f';  if ($asc >= -18239 && $asc <= -17923)    return 'g';  if ($asc >= -17922 && $asc <= -17418)    return 'h';  if ($asc >= -17417初一学生评语 && $asc <= -16475)    return 'j';  if ($asc >= -16474 && $asc <= -16213)    return 'k';  if ($asc >= -16212 && $asc <= -15641)    return 'l';  if ($asc >= -15640 && $asc <= -15166)    return 'm';  if ($asc >= -15165 && $asc <= -14923)    return 'n';  if ($asc >= -14922 && $asc <= -14915)    return 'o';  if ($asc >= -14914 && $asc <= -14631)    return 'p';  if ($asc >= -14630 && $asc <= -14150)    return 'q';  if ($asc >= -14149 && $asc <= -14091)    return 'r';  if ($asc >= -14090 && $asc <= -13319)    return 's';  if ($asc >= -13318 && $asc <= -12839)    return 't';  if ($asc >= -12838 && $asc <= -12557)    return 'w';  if ($asc >= -12556 && $asc <= -11848)    return 'x';  if ($asc >= -11847 && $asc <= -11056)    return 'y';  if ($asc >= -11055 && $asc <= -10247)    return 'z';  return rare_words($asc);}//百家姓中的生僻字function rare_words($asc=''){  $rare_arr = array(    -3652=>array('word'=>"窦",'first_char'=>'d'),    -8503=>array('word'=>"奚",'first_char'=>'x'),    -9286=>array('word'=>"酆",'first_char'=>'f'),    -7761=>array('word'=>"岑",'first_char'=>'c'),    -5128=>array('word'=>"滕",'first_char'=>'t'),    -9479=>array('word'=>"邬",'first_char'=>'w'),    -5456=>array('word'=>"臧",'first_char'=>'z'),    -7223=>array('word'=>"闵",'first_char'=>'m'),    -2877=>array('word'=>"裘",'first_char'=>'q'),    -6191=>array('word'=>"缪",'first_char'=>'m'),    -5414=>array('word'=>"贲",'first_char'=>'b'),    -4102=>array('word'=>"嵇",'first_char'=>'j'),    -8969=>array('word'=>"荀",'first_char'=>'x'),    -4938=>array('word'=>"於",'first_char'=>'y'),    -9017=>array('word'=>"芮",'first_char'=>'r'),    -2848=>array('word'=>"羿",'first_char'=>'y'),    -9477=>array('word'=>"邴",'first_char'=>'b'),    -9485=>array('word'=>"隗",'first_char'=>'k'),    -6731=>array('word'=>"宓",'first_char'=>'m'),    -冬至节9299=>array('word'=>"郗",'first_char'=>'x'),    -5905=>array('word'=>"栾",'first_char'=>'l'),    -4393=>array('word'=>"钭",'first_char'=>'t'),    -9300=>array('word'=>"郜",'first_char'=>'g'),    -8706=>array('word'=>"蔺",'first_char'=>'l'),    -3613=>array('word'=>"胥",'first_char'=>'x'),    -8777=>array('word'=>"莘",'first_char'=>'s'),    -6708=>array('word'=>"逄",'first_char'=>'p'),    -9302=>array('word'=>"郦",'first_char'=>'l'),    -5965=>array('word'=>"璩",'first_char'=>'q'),    -6745=>array('word'=>"濮",'first_char'=>'p'),    -4888=>array('word'=>"扈",'first_char'=>'h'),    -9309=>array('word'=>"郏",'first_char'=>'j'),    -5428=>array('word'=>"晏",'first_char'=>'y'),    -2849=>array('word'=>"暨",'first_char'=>'j'),    -7206=>array('水蚺word'=>"阙",'first_char'=>'q'),    -4945=>array('word'=>"殳",'first_char'=>'s'),    -9753=>array('word'=>"夔",'first_char'=>'k'),    -10041=>array('word'=>"厍",'first_char'=>'s'),    -5429=>array('word'=>"晁",'first_char'=>'c'),    -2396=>array('word'=>"訾",'first_char'=>'z'),    -7205=>array('word'=>"阚",'first_char'=>'k'),    -10049=>array('word'=>"乜",'first_char'=>'n'),    -10015=>array('word'=>"蒯",'first_char'=>'k'),    -3133=>array('word'=>"竺",'first_char'=>'z'),    -6698=>array('word'=>"逯",'first_char'=>'l'),    -9799=>array('word'=>"俟",'first_char'=>'q'),    -6749=>array('word'=>"澹",'first_char'=>'t'),    -7220=>array('word'=>"闾",'first_char'=>'l'),    -10047=>array('word'=>"亓",'first_char'=>'q'),    -10005=>array('word'=>"仉",'first_char'=>'z'),    -3417=>array('word'=>"颛",'first_char'=>'z'),    -6431=>array('word'=>"驷",'first_char'=>'s'),    -7226=>array('word'=>"闫",'first_char'=>'y'),    -9293=>array('word'=>"鄢",'first_char'=>'y'),    -6205=>array('word'=>"缑",'first_char'=>'g'),    -9764=>array('word'=>"佘",'first_char'=>'s'),    -9818=&晚上好法语gt;array('word'=>"佴",'first_char'=>'n'),    -9509=>array('word'=>"谯",'first_char'=>'q'),    -3122=>array('word'=>"笪",'first_char'=>'d'),    -9823=>array('word'=>"佟",'first_char'=>'t'),  );  if(array_key_exists($asc, $rare_arr) && $rare_arr[$asc]['first_char']){    return $rare_arr[$asc]['first_char'] ;  }el{    return null;  }}//测试:echo getfirstcharters('窦');

运行结果:

d

ps:这里再为大家提供几款本站拼音与字母相关工具供大家参考:

在线中英文根据首字母排序工具:

在线汉字转换成拼音工具:

在线中文汉字转拼音工具:

在线中文汉字拼音对照转换工具:

在线字母大小写转换工具:

本文发布于:2023-04-08 06:17:07,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/fc17374bbbc15bad156aa61479c10bab.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:PHP常用函数之获取汉字首字母功能示例.doc

本文 PDF 下载地址:PHP常用函数之获取汉字首字母功能示例.pdf

标签:在线   汉字   拼音   工具
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图