国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

PHP自定義函數獲取漢字首字母的方法

2024-05-04 23:53:08
字體:
來源:轉載
供稿:網友

本文實例講述了PHP自定義函數獲取漢字首字母的方法。分享給大家供大家參考,具體如下:

首字母很重要,可以進行排序使用。

城市列表等等。

<?php/** Created on 2016-12-1*/function getFirstCharter($str){  if (empty($str)) {    return '';  }  $fchar = ord($str{0});  if ($fchar >= ord('A') && $fchar <= ord('z'))    return strtoupper($str{0});  $s1 = iconv('UTF-8', 'gb2312', $str);  $s2 = iconv('gb2312', 'UTF-8', $s1);  $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 >= -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 null;}$firstChar = getFirstCharter('VeVb武林網');print_r($firstChar);//輸出:J?>

希望本文所述對大家PHP程序設計有所幫助。


注:相關教程知識閱讀請移步到PHP教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 贡嘎县| 桃源县| 时尚| 巨野县| 曲阳县| 镶黄旗| 绵竹市| 股票| 新民市| 濉溪县| 东辽县| 巴彦淖尔市| 闵行区| 都昌县| 肇州县| 库车县| 安龙县| 瓮安县| 萨嘎县| 江都市| 新龙县| 赤城县| 阿尔山市| 沅陵县| 区。| 黄骅市| 延边| 富蕴县| 北流市| 彭州市| 博白县| 延寿县| 健康| 九江县| 台中市| 四会市| 和平县| 姜堰市| 安塞县| 雷州市| 霞浦县|