<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<?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 "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 pinyin($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 "杜川 reload by http://dcdc723.iteye.com<br/>";
echo pinyin('杜川 by dcdc723');
?>
中文范围
[\u4E00-\u9FA5\uf900-\ufa2d]
<script type="text/javascript">
var str = "有中文?and English.";
var reg = /[\u4E00-\u9FA5\uf900-\ufa2d]/ig;
str = str.replace(reg,'哦');
document.write(str);
</script>
分享到:
相关推荐
php,mysql取汉字首字母,通过mysql自定义函数结合基本表取汉字的首字母
php 获取中文首字母 详细调用请参考附件内说明.
php按汉字首字母查询结果,还有希望能和搞php的一起交流 我的邮箱 是 meng_51xh@163.com
PHP的获取中文首字母的类,可直接用与自己的项目中
网上有现成的提取拼音首字母程序,但我查到的版本都不支持多音字提取,以前用过一个JS的支持多音字提取的函数,就把PHP版本和JS版本综合了一下,写了个类,希望对开发者有用。
php汉字转拼音及获取拼音首字母.pdf
as和php获取中文首字母,当需要处理中文字符串时,只需要重新写一个函数,用来取得一串汉字的拼音首字母
php中文汉字转拼音函数类 支持UTF8和返回首字母
汉字转全拼音或拼音首字母,支持gb2312和utf8编码 ,附带函数说明, 汉字转换为全拼音或拼音首字母 使用方法: include(ROOT_PATH.'includes/cls_chart_pinyin.php'); echo Pinyin('中国人','utf-8',false); 函数...
php汉字转拼音+读取首字母,准确高效,容易集成使用。
PHP获取字符串拼音首字母 包含多音字扩展
php获取中文首字母,获取中文首字母,使用非常方便,欢迎下载
php获取中文拼音(含生僻字,多音字,音标)支持首字母,全拼
本文为大家讲解的是使用PHP获取汉字的拼音(全部与首字母)示例,感兴趣的同学参考下。主要是包含全部拼音和获取拼音的首个字母,中文是双字节,所以需要两个字节连接起来(ASCII码的范围是在161-255)。
php汉字转拼音得到首字母的类 需要支持iconv转码 也可以自己改为mb_convert_encoding 有问题联系我
PHP中文字符串转换成首字母,文档中有详细介绍和使用方法。
PHP中文与拼音首字母的转换,如“中国”转变为“zg”
主要介绍了php获取汉字拼音首字母的方法,需要的朋友可以参考下
主要介绍了分享一段PHP制作的中文拼音首字母工具类的代码,非常的实用,代码很简单。 注: 英文的字串:不变返回(包括数字) eg .abc123 => abc123 中文字符串:返回拼音首字符 eg. 测试字符串 => CSZFC 中英混合...
取汉字的首字母,方便按照首字母排序,网上搜了很多都不是很准,这个经亲测,是比较准的。