//php获取中文字符拼音首字母
function getFirstCharter($str){
if(empty($str)){return '';}
$fchar=ord($str{});
if($fchar>=ord('A')&&$fchar<=ord('z')) return strtoupper($str{});
$s1=iconv('UTF-8','gb2312',$str);
$s2=iconv('gb2312','UTF-8',$s1);
$s=$s2==$str?$s1:$str;
$asc=ord($s{})*+ord($s{})-;
if($asc>=-&&$asc<=-) return 'A';
if($asc>=-&&$asc<=-) return 'B';
if($asc>=-&&$asc<=-) return 'C';
if($asc>=-&&$asc<=-) return 'D';
if($asc>=-&&$asc<=-) return 'E';
if($asc>=-&&$asc<=-) return 'F';
if($asc>=-&&$asc<=-) return 'G';
if($asc>=-&&$asc<=-) return 'H';
if($asc>=-&&$asc<=-) return 'J';
if($asc>=-&&$asc<=-) return 'K';
if($asc>=-&&$asc<=-) return 'L';
if($asc>=-&&$asc<=-) return 'M';
if($asc>=-&&$asc<=-) return 'N';
if($asc>=-&&$asc<=-) return 'O';
if($asc>=-&&$asc<=-) return 'P';
if($asc>=-&&$asc<=-) return 'Q';
if($asc>=-&&$asc<=-) return 'R';
if($asc>=-&&$asc<=-) return 'S';
if($asc>=-&&$asc<=-) return 'T';
if($asc>=-&&$asc<=-) return 'W';
if($asc>=-&&$asc<=-) return 'X';
if($asc>=-&&$asc<=-) return 'Y';
if($asc>=-&&$asc<=-) return 'Z';
return null;
}
echo getFirstCharter('张');

php 获取中文字符拼音首字母的更多相关文章

  1. php获取中文字符拼音首字母

    //php获取中文字符拼音首字母 function getFirstCharter($str){ if(empty($str)){ return ''; } $fchar = ord($str{0}) ...

  2. C#&Sql获取中文字符拼音首字母的方法

    C#获取字符拼音首字母,可以存储在数据库中以备将来按字母搜索的需求. public static string GetAc(string s) { try { string temp = Servic ...

  3. java 获取中文字符的首字母

    原理: GB2312编码中的中文是按照拼音排序的 注意: 一些生僻的字无法获得正确的首字母,原因是这些字都是后加入的. import java.io.UnsupportedEncodingExcept ...

  4. js 获取中文的拼音首字母

    es6 + 模块化封装 "use strict"; module.exports = { //参数,中文字符串 //返回值:拼音首字母串数组 makePy (str) { if ( ...

  5. C# 获取汉字的拼音首字母和全拼(含源码)

    C# 获取汉字的拼音首字母 一种是把所有中文字符集合起来组成一个对照表:另一种是依照汉字在Unicode编码表中的排序来确定拼音的首字母.碰到多音字时就以常用的为准(第一种方法中可以自行更改,方法为手 ...

  6. (转载)delphi中获取汉字的拼音首字母

    delphi中获取汉字的拼音首字母1.py: array[216..247] of string = ({216}'CJWGNSPGCGNESYPB' + 'TYYZDXYKYGTDJNMJ' + ' ...

  7. sql获取汉字的拼音首字母的函数

    ql获取汉字的拼音首字母   if exists (select * from sysobjects where id = object_id(N'[fn_ChineseToSpell]') and ...

  8. MySQL通过函数获取字符串汉字拼音首字母大写字符串

    DELIMITER $$ DROP FUNCTION IF EXISTS `Fun_GetPY`$$ CREATE FUNCTION `HIS`.`Fun_GetPY` (in_string VARC ...

  9. php 中文转拼音首字母问题

    <?php /* 中文汉字转拼音首字母的PHP简易实现方法. 要求: 只能是GB2312码表里面中文字符 转换得到字符串对应的拼音首字母大写. 用法: echo zh2py::conv('Chi ...

随机推荐

  1. Python 2.7_First_try_爬取阳光电影网_20161206

    之前看过用Scrapy 框架建立项目爬取 网页解析时候用的Xpath进行解析的网页元素 这次尝试用select方法匹配元素 1.入口爬取页面 http://www.ygdy8.com/index.ht ...

  2. VC++ 在控件上写字时 字体的设置技巧

    //人物照片下方的文字 CFont* nFont = &afxGlobalData.fontRegular; CFont* oFont = pDc->SelectObject(nFont ...

  3. Linux(centos)系统各个目录的作用详解

    Linux(centos)系统各个目录的作用详解 文件系统的类型 LINUX有四种基本文件系统类型:普通文件.目录文件.连接文件和特殊文件,可用file命令来识别. 普通文件:如文本文件.C语言元代码 ...

  4. 《Linux内核设计与实现》读书笔记 第二章 从内核出发

    一.获取内核源码 1. Git git实际上是一种开源的分布式版本控制工具. Linux作为一个开源的内核,其源代码也可以用git下载和管理 - 获取最新提交到版本树的一个副本 - $ git clo ...

  5. js中this对象,call,apply

  6. wget net-tools

    新安装的centos7 minimal 没有安装 wget 需要安装一下,才能安装lnmp yum -y install wget yum -y install net-tools

  7. The certificate used to sign “AppName” has either expired or has been revoked. An updated certificate is required to sign and install the application解决

    问题 The certificate used to sign "AppName" has either expired or has been revoked. An updat ...

  8. C++新特性(类)(转载)

    C++新特性(类)里面讲的很清楚,转给大家分享一下 类机制: 类是对某一类对象的抽象:对象是某一类的实例: 类是一种复杂的数据类型,将不同类型的数据和这些数据相关的操作封装在一起的集合体: 通过一道程 ...

  9. JNI Local Reference Changes in ICS

    [This post is by Elliott Hughes, a Software Engineer on the Dalvik team. — Tim Bray] If you don’t wr ...

  10. 2.Java对象创建

    1. 对象的创建 虚拟机遇到一条new指令时,首先将去检查这个指令的参数是否能在常量池中定位到一个类的符号引用,并且检查这个符号引用代表的类是否已被加载.解析和初始化过.如果没有,那必须先执行相应的类 ...