PHP获取中文汉字首字母方法
function getFirstLetter($str){
$fchar = ord($str{0});
if($fchar >= ord("A") and $fchar <= ord("z") )return strtoupper($str{0});
$s1 = iconv("UTF-8","gb2312", $str);
$s2 = iconv("gb2312","UTF-8", $s1);
if($s2 == $str){$s = $s1;}
else{$s = $str;}
$asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
if($asc >= -20319 and $asc <= -20284) return "A";
if($asc >= -20283 and $asc <= -19776) return "B";
if($asc >= -19775 and $asc <= -19219) return "C";
if($asc >= -19218 and $asc <= -18711) return "D";
if($asc >= -18710 and $asc <= -18527) return "E";
if($asc >= -18526 and $asc <= -18240) return "F";
if($asc >= -18239 and $asc <= -17923) return "G";
if($asc >= -17922 and $asc <= -17418) return "I";
if($asc >= -17417 and $asc <= -16475) return "J";
if($asc >= -16474 and $asc <= -16213) return "K";
if($asc >= -16212 and $asc <= -15641) return "L";
if($asc >= -15640 and $asc <= -15166) return "M";
if($asc >= -15165 and $asc <= -14923) return "N";
if($asc >= -14922 and $asc <= -14915) return "O";
if($asc >= -14914 and $asc <= -14631) return "P";
if($asc >= -14630 and $asc <= -14150) return "Q";
if($asc >= -14149 and $asc <= -14091) return "R";
if($asc >= -14090 and $asc <= -13319) return "S";
if($asc >= -13318 and $asc <= -12839) return "T";
if($asc >= -12838 and $asc <= -12557) return "W";
if($asc >= -12556 and $asc <= -11848) return "X";
if($asc >= -11847 and $asc <= -11056) return "Y";
if($asc >= -11055 and $asc <= -10247) return "Z";
return null;
}
PHP获取中文汉字首字母方法的更多相关文章
- sqlservice 查询该字段的值是否为数字、不包含a-z字母、获取中文的首字母
select zjm from xskh where guid_yw='e6ee44f3-98ab-4446-bd9b-db2e525d3b24' and zjm not like '%[ABCDE ...
- 获取中文的首字母demo
import net.sourceforge.pinyin4j.PinyinHelper; /** * * @Title: getPinYinHeadChar * @Description: TODO ...
- excel 获取中文拼音首字母
excel 获取中文拼音首字母 CreateTime--2018年5月31日08:50:42 Author:Marydon 1.情景展示 想要获取姓名的拼音首字母 2.实现方式 通过使用excel ...
- [Python] Python 获取中文的首字母 和 全部拼音首字母
Python 获取中文的首字母 和 全部拼音首字母 代码如下: import pinyin def getStrAllAplha(str): return pinyin.get_initial(str ...
- JS获取中文拼音首字母,并通过拼音首字母高速查找页面内的中文内容
实现效果: 图一: 图二: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdGVzdGNzX2Ru/font/5a6L5L2T/fontsize/400/f ...
- python 获取中文拼音首字母;判断文件夹是否存在
1.如何获取中文字符串的首字母 import pinyin #输入name def get_pinyin_first_alpha(name): return "".join([i[ ...
- php 获取中文字符串首字母
<?php $limit=array( //gb2312 拼音排序 array(45217,45252), //A array(45253,45760), //B array(45761,463 ...
- java获取中文拼音首字母
import net.sourceforge.pinyin4j.PinyinHelper; public class PinyinHelperUtil { /** * 得到中文首字母(中国 -> ...
- 【PHP原生】获取字符串所有汉字首字母和首个汉字首字母
1.废话不多说,看代码,获取字符串汉字首字母,兼容GBK和UTF-8 <?php //获取单个汉字拼音首字母.注意:此处不要纠结.汉字拼音是没有以U和V开头的 function getfirst ...
随机推荐
- HTML5音乐可视化
环境搭建 1,安装nodejs和Git,配置环境变量2,安装express,npm install -g express-generator3,创建项目,express -e music(项目名称)4 ...
- JS实现用键盘控制DIV上下左右+放大缩小与变色
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- js在线题目
在线题目: https://www.nowcoder.com/ta/js-assessment
- zepto 获取checked selected元素
原文阅读:WISER CODER 1. Zepto.js and the :selected and :checked selectors 如果你已经看上了jQuery那残弱的表兄弟, Zepto.j ...
- 关于DLL中Resources文件修改
1.先用IL DASM工具将所需要修改的DLL进行文件转换成IL文件,其中*.il文件就是代码,*.resources,这个文件就是资源. 2.找到需要修改的resources文件 //新文件 IRe ...
- 深搜基础题目 杭电 HDU 1241
HDU 1241 是深搜算法的入门题目,递归实现. 原题目传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1241 代码仅供参考,c++实现: #incl ...
- LeetCode之ReverseWorldString
题目:将一个英文句子翻转,比如:the sky is blue 翻转后变为:blue is sky the 分析:我的实现方法是,利用栈将单词存储起来,然后再顺序拿出来,单词进栈还需注意添加空格. 主 ...
- Lucene学习之初步了解
全文搜索 比如,我们一个文件夹中,或者一个磁盘中有很多的文件,记事本.world.Excel.pdf,我们想根据其中的关键词搜索包含的文件.例如,我们输入Lucene,所有内容含有Lucene的文件就 ...
- Linux08--Shell程序设计03 shell script
第一个Shell脚本——HelloWorld [root@localhost ~]# vi sh01.sh #!/bin/bash #!表明使用哪种shell # this is my first s ...
- laravel5.1框架简介及安装
最近自己出来实习了,进入了一个新的环境,不仅是生活中,在代码和架构中也完全是一个新的架构.由于公司使用laravel5.1框架,所以最近学习了laravel5.1框架,好了接下来就简单介绍一下lara ...