php将汉字转换为拼音和得到词语首字母(三)
<?php
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 'H';
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('者(儋@*a,儋1子豪a放1这是中文字符串'); ?>
php将汉字转换为拼音和得到词语首字母(三)的更多相关文章
- php将汉字转换为拼音和得到词语首字母(一)
<?php /** * 修复二分法查找方法 * 汉字拼音首字母工具类 * 注: 英文的字串:不变返回(包括数字) eg .abc123 => abc123 * 中文字符串:返回拼音首字符 ...
- php将汉字转换为拼音和得到词语首字母(四)
<?php function getfirstchar($s0){ $firstchar_ord=ord(strtoupper($s0{0})); if (($firstchar_ord> ...
- php将汉字转换为拼音和得到词语首字母(二)
<?php class Pinyin{ private $_outEncoding = "GB2312"; public function getPinyin($str,$p ...
- swift把汉字转换为拼音,并且截取首字母做索引用
var transformContents = CFStringCreateMutableCopy(nil, 0, "咋啊的看到回复阿斯顿发货发哦iasdifas")CFStrin ...
- Swift - 把汉字转换为拼音,并且截取首字母做索引用
var transformContents = CFStringCreateMutableCopy(nil, 0, "咋啊的看到回复阿斯顿发货发哦iasdifas") CFStri ...
- MySQL按照汉字的拼音排序、按照首字母分类
项目中有时候需要按照汉字的拼音排序,比如联系人列表.矿物分类等,有的还需要按拼音字母从A到Z分类显示. 如果存储汉字的字段编码使用的是GBK字符集,因为GBK内码编码时本身就采用了拼音排序的方法(常用 ...
- JAVA实现汉字转换为拼音 pinyin4j/JPinyin
在项目中经常会遇到需求用户输入汉字后转换为拼音的场景,比如说通讯录,就会要求按名字首字符发音排序,如果自己写实现这方面的功能是个很好大的工程,还好网上有公开的第三方jar支持转换,结合网上很多前辈的代 ...
- iOS将汉字转换为拼音
将汉字转换为拼音 - (NSString *)chineseToPinyin:(NSString *)chinese withSpace:(BOOL)withSpace { CFStringRef h ...
- 使用PinYin4j.jar将汉字转换为拼音
package com.Test.util; import net.sourceforge.pinyin4j.PinyinHelper; import net.sourceforge.pinyin4j ...
随机推荐
- Java:多线程,线程池,用Executors静态工厂生成常用线程池
一: newSingleThreadExecutor 创建一个单线程的线程池,以无界队列方式运行.这个线程池只有一个线程在工作(如果这个唯一的线程因为异常结束,那么会有一个新的线程来替代它.)此线程池 ...
- Codeforces Round #262 (Div. 2) C
题目: C. Present time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Linux下nagios网络监控与/proc/net/tcp文件详解
问题描述:nagios自带的check_antp太过简约,除了状态统计输出外,什么参数都不提供.在面对不同应用服务器时,报警就成了很大问题. 问题描述:nagios自带的check_antp太过简约, ...
- Viso Professional 2013版本激活(office 系列产品 -- visio 2013 / project 2013 破解工具 - KMSpico)
背景: 环境是 win7, 64 bit 装了 visio 2013 , 可以却不能用它来画图,在网上找了一些破解工具,大都不能解决问题.网上不靠谱的广告型文章太多了,比较头痛. 所幸,终于找到正确的 ...
- [na]wac无线控制器集中转发部署的几种情况
1,背景: sta属于vlan20.ap属于vlan20.本地转发. 现象: Ap获取到的地址是vlan20的地址池的某地址 用户无法获取地址. 注意:本地转发,ap获取地址dhcp包不走隧道.用户获 ...
- iphone CGContextSetLineWidth 画线的问题
转自:http://blog.csdn.net/jxncwzb/article/details/6267154 CGContextRef context = UIGraphicsGetCurrentC ...
- mysql 下载
mysql 下载
- iOS_20_微博Dock的尾随切换
终于效果图:Dock尾随HomeVC一起切换 要求: 当点击HomeVC里面的微博列表的某一行时候, push到StatusDetail微博详情控制器,而且Dock也一起消失 当点击StatusDet ...
- rabbitmq增加vhost
查看当前rabbitmq上的vhost列表: # rabbitmqctl list_vhosts Listing vhosts ... / vhost2 添加名为demo的vhost虚似主机: rab ...
- JDK自带工具之问题排查场景示例
最近看到了大量关于java性能调优.故障排查的文章,自己也写了一篇< Java调优经验谈 >.接着此篇文章,其实一直打算写写一些常用调优工具以及它们的惯常用法的.后来在http://jav ...