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 ...
随机推荐
- supervisor 配置篇
1,配置管理进程 进程管理配置参数,不建议全都写在supervisord.conf文件中,应该每个进程写一个配置文件放在include指定的目录下包含进supervisord.conf文件中. 1&g ...
- 如何用css给input的placeholder设置颜色
我在做页面的时候遇到过这种情况,在input标签中有默认字,但是设计稿上的颜色和input标签中的placeholder的默认颜色不一致.虽然我们可以在js中写出,但是有点过于麻烦了. 所以我就用cs ...
- nginx + ngx_lua安装测试
nginx lua模块淘宝开发的nginx第三方模块,它能将lua语言嵌入到nginx配置中,从而使用lua就极大增强了nginx的能力.nginx以高并发而知名,lua脚本轻便,两者的搭配堪称完美. ...
- 使用dockerfile 创建ubuntu ssh镜像
############################################################ # Dockerfile to build ubunto ssh contai ...
- (1.2)DML增强功能-4大排名函数与top ties/tablesample
关键字:sql server窗口函数.分析函数.四大窗口函数 1.row_number() over( partition by column order by column) (1)测试数据 (2 ...
- 百度天气接口api
百度天气接口 以GET形式提交,返回JSON或XML URL:http://api.map.baidu.com/telematics/v3/weather?location={城市名}&out ...
- Jenkins时区设置
系统管理->脚本命令行 System.setProperty('org.apache.commons.jelly.tags.fmt.timeZone', 'Asia/Shanghai')
- 4.6 Routing -- Rendering A Tempalte
1. route handler一个重要的任务就是渲染合适的模板到屏幕. 2. 默认的,一个route handler将会呈现模板到最近的父模板. app/router.js Router.map(f ...
- 2018 Multi-University Training Contest 4 Solution
A - Problem A. Integers Exhibition 留坑. B - Problem B. Harvest of Apples 题意:计算$\sum_{i = 0}^{i = m}C( ...
- poj1329 Circle Through Three Points
地址:http://poj.org/problem?id=1329 题目: Circle Through Three Points Time Limit: 1000MS Memory Limit: ...