您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息

简单的php中文转拼音的实现_PHP教程

2024/4/16 10:01:47发布11次查看
不多说,代码送上:
 ='5.0') ? array_combine($_tdatakey, $_tdatavalue) : _array_combine($_tdatakey, $_tdatavalue);
arsort($_data);
reset($_data);
if($_code != 'gb2312') $_string = _u2_utf8_gb($_string);
$_res = '';
for($i=0; $i{
$_p = ord(substr($_string, $i, 1));
if($_p>160) { $_q = ord(substr($_string, ++$i, 1)); $_p = $_p*256 + $_q - 65536; }
$_res .= _pinyin($_p, $_data);
}
return preg_replace(/[^a-z0-9]*/, '', $_res);
}
function _pinyin($_num, $_data)
{
if ($_num>0 && $_numelseif($_num-10247) return '';
else {
foreach($_data as $k=>$v){ if($vreturn $k;
}
}
function _u2_utf8_gb($_c)
{
$_string = '';
if($_c elseif($_c {
$_string .= chr(0xc0 | $_c>>6);
$_string .= chr(0x80 | $_c & 0x3f);
}elseif($_c $_string .= chr(0xe0 | $_c>>12);
$_string .= chr(0x80 | $_c>>6 & 0x3f);
$_string .= chr(0x80 | $_c & 0x3f);
} elseif($_c $_string .= chr(0xf0 | $_c>>18);
$_string .= chr(0x80 | $_c>>12 & 0x3f);
$_string .= chr(0x80 | $_c>>6 & 0x3f);
$_string .= chr(0x80 | $_c & 0x3f);
}
return iconv('utf-8', 'gb2312', $_string);
}
function _array_combine($_arr1, $_arr2)
{
for($i=0; $ireturn $_res;
}
//用法:
//第二个参数留空则为gb1232编码
//echo pinyin('安徽');
//第二个参数随意设置则为utf-8编码
echo pinyin('安徽软件有限公司',1);
?>
http://www.bkjia.com/phpjc/732578.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/732578.htmltecharticle不多说,代码送上: ?php function pinyin($_string, $_code='gb2312') { $_datakey = a|ai|an|ang|ao|ba|bai|ban|bang|bao|bei|ben|beng|bi|bian|biao|bie|bin|bing|bo|bu|ca|cai|ca...
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录