php---------取汉字的第一个字的首字母
开发中用到的方法,取出第一个汉字的首字母;
/**
* 取汉字的第一个字的首字母
* @param string $str
* @return string|null
*/
function getFirstChar($str) {
if (empty($str)) {
return '';
} $fir = $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;
if (!isset($s[0]) || !isset($s[1])) {
return '';
} $asc = ord($s[0]) * 256 + ord($s[1]) - 65536; if (is_numeric($str)) {
return $str;
} if (($asc >= -20319 && $asc <= -20284) || $fir == 'A') {
return 'A';
}
if (($asc >= -20283 && $asc <= -19776) || $fir == 'B') {
return 'B';
}
if (($asc >= -19775 && $asc <= -19219) || $fir == 'C') {
return 'C';
}
if (($asc >= -19218 && $asc <= -18711) || $fir == 'D') {
return 'D';
}
if (($asc >= -18710 && $asc <= -18527) || $fir == 'E') {
return 'E';
}
if (($asc >= -18526 && $asc <= -18240) || $fir == 'F') {
return 'F';
}
if (($asc >= -18239 && $asc <= -17923) || $fir == 'G') {
return 'G';
}
if (($asc >= -17922 && $asc <= -17418) || $fir == 'H') {
return 'H';
}
if (($asc >= -17417 && $asc <= -16475) || $fir == 'J') {
return 'J';
}
if (($asc >= -16474 && $asc <= -16213) || $fir == 'K') {
return 'K';
}
if (($asc >= -16212 && $asc <= -15641) || $fir == 'L') {
return 'L';
}
if (($asc >= -15640 && $asc <= -15166) || $fir == 'M') {
return 'M';
}
if (($asc >= -15165 && $asc <= -14923) || $fir == 'N') {
return 'N';
}
if (($asc >= -14922 && $asc <= -14915) || $fir == 'O') {
return 'O';
}
if (($asc >= -14914 && $asc <= -14631) || $fir == 'P') {
return 'P';
}
if (($asc >= -14630 && $asc <= -14150) || $fir == 'Q') {
return 'Q';
}
if (($asc >= -14149 && $asc <= -14091) || $fir == 'R') {
return 'R';
}
if (($asc >= -14090 && $asc <= -13319) || $fir == 'S') {
return 'S';
}
if (($asc >= -13318 && $asc <= -12839) || $fir == 'T') {
return 'T';
}
if (($asc >= -12838 && $asc <= -12557) || $fir == 'W') {
return 'W';
}
if (($asc >= -12556 && $asc <= -11848) || $fir == 'X') {
return 'X';
}
if (($asc >= -11847 && $asc <= -11056) || $fir == 'Y') {
return 'Y';
}
if (($asc >= -11055 && $asc <= -10247) || $fir == 'Z') {
return 'Z';
} return '';
}
php---------取汉字的第一个字的首字母的更多相关文章
- SQL汉字转拼音函数-支持首字母、全拼
SQL汉字转拼音函数-支持首字母.全拼 FROM :http://my.oschina.net/ind/blog/191659 作者不详 --方法一sqlserver汉字转拼音首字母 --调用方法 s ...
- 使用PHP获取汉字的拼音(全部与首字母)
<?php /** * 取汉字拼音 * edit by www.jbxue.com */ class GetPingYing { private $pylist = array( 'a'=> ...
- java汉字转拼音以及得到首字母通用方法
package oa.common.utils; import net.sourceforge.pinyin4j.PinyinHelper; import net.sourceforge.piny ...
- java根据汉字获取全拼和首字母
import net.sourceforge.pinyin4j.PinyinHelper; import net.sourceforge.pinyin4j.format.HanyuPinyinCase ...
- vue集成汉字转拼音或提取首字母
需求: 有时我们为了节省用户的维护量,需要根据中文生成出相应的拼音和缩写 解决: 此方法是利用汉字和Unicode编码对应找到相应字母 一.编写汉字和编码 ...
- 【Java】使用pinyin4j获取汉字的全拼或首字母
汉字转拼音的工具类,常用于做汉字拼音的模糊查询. https://www.cnblogs.com/htyj/p/7891918.html
- php里获取第一个中文首字母并排序
需求里结算首页需要按门店的首字母A-Z排序.我的数据结构原本是这样的: Array ( [0] => Array ( [sid] => 2885842 [recetcstoredpay] ...
- MySQL数据库获取多个汉字拼音的首字母函数
需求简介:最近的一个项目,想实现如下图所示的显示效果.很明显,如果能够获取对应的汉字词组中每个汉字的拼音首字母就可以实现了,如果是固定的几组汉字,人为的拼一下就可以 了,不过项目中有多处功能需要这个效 ...
- Java 获取汉字串首字母并大写和获取汉字的全拼,英文字符不变
在开发中我们难免会遇到需要提出汉字中的拼音的首字母.提出汉字的拼音,接着便介绍一个工具类 pinyin4j.jar,首先需要下载 jar 包. Pinyin4j是一个功能强悍的汉语拼音工具包,是sou ...
随机推荐
- 170719、springboot编程之异步调用@Async
1.在pom.xml中增加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artif ...
- 公民身份号码校验码算法(C#版)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- Oracle HA 之 基于活动数据库复制配置oracle 11.2 dataguard
规划:主库:db_name=dbking db_unique_name=dbkingpri 备库:db_name=dbking ...
- mysql_commit() COMMIT ROLLBACK 提交 回滚 连接释放
MySQL :: MySQL 8.0 Reference Manual :: 28.7.7.6 mysql_commit() https://dev.mysql.com/doc/refman/8.0/ ...
- Redis缓冲区设置
对于Redis服务器的输出(也就是命令的返回值)来说,其大小通常是不可控制的.有可能一个简单的命令,能够产生体积庞大的返回数据.另外也有可能因为执行了太多命令,导致产生返回数据的速率超过了往客户端发送 ...
- 理解Java异常处理机制的机理
重看异常机制的时候觉得抓到了点机理上的精髓,所以来说一下,对初学者应该会有些帮助 JAVA中的异常机制 从机制上由[产生异常][抛出异常][捕捉异常][异常处理]组成 从形式上又分为四种: 运行时 ...
- T-SQL练习题
转自:http://www.cnblogs.com/jenrrychen/p/5348546.html 1 - 3 题: 数据表结构: OrderID ProductID OrderDate Sal ...
- mysql 数据操作 单表查询 group by 聚合函数
强调: 如果我们用unique的字段作为分组的依据,则每一条记录自成一组,这种分组没有意义 多条记录之间的某个字段值相同,该字段通常用来作为分组的依据 如果按照每个字段都是唯一的进行分组,意味着按照这 ...
- elasticsearch-hadoop使用
elasticsearch-hadoop是一个深度集成Hadoop和ElasticSearch的项目,也是ES官方来维护的一个子项目,通过实现Hadoop和ES之间的输入输出,可以在Hadoop里面对 ...
- python学习笔记(二十九)为什么python的多线程不能利用多核CPU
问题:为什么python的多线程不能利用多核CPU,但是咱们在写代码的时候,多线程的确是在并发,而且还比单线程快原因:因为GIL,python只有一个GIL,运行python时,就要拿到这个锁才能执行 ...