//取汉字的asc区间然后返回汉字首字母了,代码如下:
header("Content-type: text/html; charset=utf-8");
function getfirstchar($s0){
$fchar = ord($s0{0});
if($fchar >= ord("A") and $fchar <= ord("z") ){
return strtoupper($s0{0});
} $s1 = iconv("UTF-8","gb2312", $s0);
$s2 = iconv("gb2312","UTF-8", $s1); if($s2 == $s0){$s = $s1;}else{$s = $s0;}
$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;
} function pinyin1($zh){
$ret = "";
$s1 = iconv("UTF-8","gb2312", $zh);
$s2 = iconv("gb2312","UTF-8", $s1);
if($s2 == $zh){$zh = $s1;}
for($i = 0; $i < strlen($zh); $i++){
$s1 = substr($zh,$i,1);
$p = ord($s1);
if($p > 160){
$s2 = substr($zh,$i++,2);
$ret .= getfirstchar($s2);
}else{
$ret .= $s1;
}
}
return $ret;
}
echo "这是中文字符串<br/>";
echo pinyin1('这是中文字符串');

php实现获取汉字的首字母实例的更多相关文章

  1. C# 获取汉字拼音首字母

    最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来. 十年河东十年河西,莫欺少年穷 学无止境,精益求精   本节探讨C#获取汉字拼音首字母的方法: 代码类东西, ...

  2. C# 获取汉字拼音首字母/全拼

    最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来. 十年河东十年河西,莫欺少年穷 学无止境,精益求精   本节探讨C#获取汉字拼音首字母的方法: 代码类东西, ...

  3. java获取汉字拼音首字母 --转载

    在项目中要更能根据某些查询条件(比如姓名)的首字母作为条件进行查询,比如查一个叫"李晓明"的人,可以输入'lxm'.写了一个工具类如下: import java.io.Unsupp ...

  4. Android -- 获取汉字的首字母

    转换                                                                                             获取一个汉 ...

  5. php实现获取汉字的首字母

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...

  6. JAVA获取汉字拼音首字母

    package com.common.util; import java.io.UnsupportedEncodingException; /** * 取得给定汉字串的首字母串,即声母串 * Titl ...

  7. php获取汉字拼音首字母的方法

    现实中我们经常看到这样的说明,排名不分先后,按姓名首字母进行排序.这是中国人大多数使用的排序方法.那么在php程序中该如何操作呢? 下面就分享一下在php程序中获取汉字拼音的首字母的方法,在网上搜到的 ...

  8. Java 获取汉字串首字母并大写和获取汉字的全拼,英文字符不变

    在开发中我们难免会遇到需要提出汉字中的拼音的首字母.提出汉字的拼音,接着便介绍一个工具类 pinyin4j.jar,首先需要下载 jar 包. Pinyin4j是一个功能强悍的汉语拼音工具包,是sou ...

  9. C/C++ 获取汉字拼音首字母

    #include <stdint.h> #include <stdio.h> #include <ctype.h> #include <string.h> ...

随机推荐

  1. web2.0的几个开源项目

    web2.0的几个开源项目   Diggclone-开源digg类程序官方:http://www.talkingpixels.org/diggclone/index.php演示:同digg.com类似 ...

  2. -_-#【Better Code】字符串匹配

    提高 web 应用性能之 JavaScript 性能调优

  3. 【动态规划】HDU 1081 & XMU 1031 To the Max

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1081 http://acm.xmu.edu.cn/JudgeOnline/problem.php?i ...

  4. 后缀.aspx.cs是什么软件的生成的

    ASP.NET技术 aspx ——ASP.NET文件(网页) aspx.cs ——ASP.NET文件中的代码页(与上面的对应) asp.net是微软公司推出的新一代网站程序开发架构,ASP.NET技术 ...

  5. Java---IO加强(2)

    转换流 ★转换流功能1:充当字节流与字符流之间的桥梁 需求:模拟英文聊天程序,要求: (1) 从键盘录入英文字符,每录一行就把它转成大写输出到控制台: (2) 保存聊天记录到字节流文件. 要求1的设计 ...

  6. 酷派D530刷机指引之民间ROM

    为什么要刷民间ROM? 下图左边是官方ROM,右边是民间ROM,单单看"程序内存"这一项,这个问题的答案应该无需多言: 选择民间ROM就跟找对象一样,没有最好的,只有最适合自己的, ...

  7. File System Minifilter Drivers(文件系统微型过滤驱动)入门

    问题: 公司之前有一套文件过滤驱动,但是在实施过程中经常出现问题,现在交由我维护.于是在边看代码的过程中,一边查看官方资料,进行整理. 这套文件过滤驱动的目的只要是根据应用层下发的策略来控制对某些特定 ...

  8. [Design Pattern] Singleton Pattern 简单案例

    Singleton Pattern, 即单例模式,用于获取类的一个对象,该对象在整个应用中是其类的唯一对象.单例模式属于创建类的设计模式. SingleObject 作为单例类,内含了一个静态私有的 ...

  9. JNI- java.lang.UnsatisfiedLinkError: Native method not found

    http://stackoverflow.com/questions/24566127/jni-java-lang-unsatisfiedlinkerror-native-method-not-fou ...

  10. 配置WifiConfiguration

    public WifiConfiguration CreateWifiInfo(String SSID, String Password, int Type) { WifiConfiguration  ...