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#获取汉字拼音首字母的方法: 代码类东西, ...
随机推荐
- User has no SELECT privilege on V$SESSION
今天是2013-09-20,最近心情一直很差,但是也不能不学习啊,无论怎么样,自己学到 的东西永远都是自己的.加油! 使用dbms_xplan.display_cursor function ...
- Ext 怎么发ajax请求
Ext3.3完整包 Ext3.3中文文档 数据表的结构是:数据表table > 记录record > 字段 store的结构是: Ext.data.Store > Ext.dat ...
- windows7旗舰版下载出现蓝屏代码50怎么办?
windows7旗舰版下载出现蓝屏代码50怎么办?电脑蓝屏BCCode:50. 问题事件名称: BlueScreen OS 版本: 6.1.7601.2.1.0.256.1 区域设置 ID: 2052 ...
- OC基础7:变量和数据类型
"OC基础"这个分类的文章是我在自学Stephen G.Kochan的<Objective-C程序设计第6版>过程中的笔记. 1.有时候初始化需要让对象带有初始值,那么 ...
- poj2392 Space Elevator(多重背包)
http://poj.org/problem?id=2392 题意: 有一群牛要上太空.他们计划建一个太空梯-----用一些石头垒.他们有K种不同类型的石头,每一种石头的高度为h_i,数量为c_i,并 ...
- 【Android】Intent中使用Extra传递数据
传值方法一 Intent intent = new Intent(); Bundle bundle = new Bundle(); //该类用作携带数据 bundle.putString(" ...
- 树形控件CTreeCtrl的使用
树形控件在界面编程中应用十分普遍,如在资源管理器中和树形结构显示书的文件夹等,我们一步步研究树形控件的使用. 在对话框界面上首先拖动创建一个树,一般我们改变三个属性: Has Buttons显示带有& ...
- Performing a full database disaster recovery with RMAN
Performing a full database disaster recovery with RMAN1. Make the RMAN backup set pieces available.2 ...
- SqlDataAdapter.Update()方法与SqlCommandBuilder(转)
用SqlDataAdapter操纵数据集时最常用到的就是Fill()与Update()方法.Fill()填充DataSet或DataTable,而Update()就是将DataSet或DataTabl ...
- android 后台运行
改写返回键事件监听,使得back键功能类似home键,让Acitivty退至后台时不被系统销毁,代码如下: public boolean onKeyDown(int keyCode, KeyEvent ...