php汉字生成首字母
function getfirstchar($s0){
$fchar = ord($s0{});
if($fchar >= ord("A") and $fchar <= ord("z") )return strtoupper($s0{});
$s1 = iconv("UTF-8","gb2312", $s0);
$s2 = iconv("gb2312","UTF-8", $s1);
if($s2 == $s0){$s = $s1;}else{$s = $s0;}
$asc = ord($s{}) * + ord($s{}) - ;
if($asc >= - and $asc <= -) return "A";
if($asc >= - and $asc <= -) return "B";
if($asc >= - and $asc <= -) return "C";
if($asc >= - and $asc <= -) return "D";
if($asc >= - and $asc <= -) return "E";
if($asc >= - and $asc <= -) return "F";
if($asc >= - and $asc <= -) return "G";
if($asc >= - and $asc <= -) return "I";
if($asc >= - and $asc <= -) return "J";
if($asc >= - and $asc <= -) return "K";
if($asc >= - and $asc <= -) return "L";
if($asc >= - and $asc <= -) return "M";
if($asc >= - and $asc <= -) return "N";
if($asc >= - and $asc <= -) return "O";
if($asc >= - and $asc <= -) return "P";
if($asc >= - and $asc <= -) return "Q";
if($asc >= - and $asc <= -) return "R";
if($asc >= - and $asc <= -) return "S";
if($asc >= - and $asc <= -) return "T";
if($asc >= - and $asc <= -) return "W";
if($asc >= - and $asc <= -) return "X";
if($asc >= - and $asc <= -) return "Y";
if($asc >= - and $asc <= -) 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 = ; $i < strlen($zh); $i++){
$s1 = substr($zh,$i,);
$p = ord($s1);
if($p > ){
$s2 = substr($zh,$i++,);
$ret .= getfirstchar($s2);
}else{
$ret .= $s1;
}
}
return $ret;
}
echo "这是中文字符串<br/>";
echo pinyin1('这是中文字符串');
php汉字生成首字母的更多相关文章
- AutoCompleteTextView输入汉字拼音首字母实现过滤提示(支持多音字,Filterable的使用)
AutoCompleteTextView具有输入提示的功能,但是它的这种提示不适合对股票列表的过滤,如果你玩过股票软件,就会知道只要输入股票名称的首字母或股票代码就会出现符合匹配的股票,这种过滤怎么实 ...
- HBuilder+eclipse开发:使用ajax异步传值生成首字母索引
使用ajax异步传值生成首字母索引大致有以下几个步骤: 1.服务器端使用servlet提取出数据库里的数据; 2.使用首字母工具类对数据进处理得到首字母; 3.再将首字母和数据一一对应存入json数组 ...
- java获取汉字拼音首字母 --转载
在项目中要更能根据某些查询条件(比如姓名)的首字母作为条件进行查询,比如查一个叫"李晓明"的人,可以输入'lxm'.写了一个工具类如下: import java.io.Unsupp ...
- C# 获取汉字拼音首字母
最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来. 十年河东十年河西,莫欺少年穷 学无止境,精益求精 本节探讨C#获取汉字拼音首字母的方法: 代码类东西, ...
- Android -- 获取汉字的首字母
转换 获取一个汉 ...
- sql 汉字转首字母拼音
从网络上收刮了一些,以备后用 create function fun_getPY(@str nvarchar()) returns nvarchar() as begin declare @word ...
- 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 ...
- JAVA获取汉字拼音首字母
package com.common.util; import java.io.UnsupportedEncodingException; /** * 取得给定汉字串的首字母串,即声母串 * Titl ...
- C# 获取汉字拼音首字母/全拼
最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来. 十年河东十年河西,莫欺少年穷 学无止境,精益求精 本节探讨C#获取汉字拼音首字母的方法: 代码类东西, ...
随机推荐
- docker学习笔记(1)
(1)Docker介绍 关于Docker的介绍,我就不列举出来了.到百度.谷歌搜索.非常多介绍文章.以下我给出官网的介绍:https://www.docker.com/whatisdocker/ (2 ...
- 字符编码介绍及java中的应用
字符编码,就是对日常的控制符号.文字和常用符号的二进制表示.为了准确的表示如何编号,怎么生产八位字节流,Unicode Technical Report (UTR) #17提出现代编码模型的5个层次: ...
- mesos博客集
http://dongxicheng.org/category/apache-mesos/
- MVC零基础学习整理(一)
1.Mvc程序的启动页的设置:修改程序的Global.asax文件
- T-SQL索引
索引 使用索引可以提高查询速度,不是越多越好,会损耗存储空间.应用于出现在where子句中的列建立索引.可以使用sql server 内置工具Profiler捕捉在SQL Server实例上执行的活动 ...
- @property属性
1. 读写属性(readwrite/ readonly) 默认为readwrite,表示该属性既可以读取,也可以给该属性变量赋值:readonly则表示只能读取该属性变量. 2. 原子属性 (atom ...
- Swift语法基础入门四(构造函数, 懒加载)
Swift语法基础入门四(构造函数, 懒加载) 存储属性 具备存储功能, 和OC中普通属性一样 // Swfit要求我们在创建对象时必须给所有的属性初始化 // 如果没办法保证在构造方法中初始化属性, ...
- iOS集成微信支付
微信支付的开发 前言:之前听说过微信支付有很多坑,其实没有想象的那么坑,整体感觉很容易上手,按照它的流程来不会有错!PS:官方的流程看的TMD烦,好啦,废话有点多,进入开发.(ps:每个微信的版本一直 ...
- C#6 冒泡 折半查找 二维数组
人类思维--计算机逻辑思维 逻辑思维--代码实现 写书法: 描红--临摹--碑贴--自成一体--草 章节复习: 数组:一维,二维,多维 一维:豆角.连续,同一类型. 定义:数据类型[] 数组名=new ...
- [string]Regular Expression Matching
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...