php 输入汉字,查出对应的拼音
来源:互联网 发布:淘宝刷流量软件 编辑:程序博客网 时间:2024/04/28 03:14
<?php
$pinyins = Array();
//获取一串中文字符的拼音 ishead=0 时,输出全拼音 ishead=1时,输出拼音首字母
function GetPinyin($str,$ishead=0,$isclose=1){
global $pinyins;
$restr = "";
$str = trim($str);
$slen = strlen($str);
if($slen<2) return $str;
if(count($pinyins)==0){
$fp = fopen("./pinyin.db","r");
while(!feof($fp)){
$line = trim(fgets($fp));
$pinyins[$line[0].$line[1]] = substr($line,3,strlen($line)-3);
}
fclose($fp);
}
for($i=0;$i<$slen;$i++){
if(ord($str[$i])>0x80)
{
$c = $str[$i].$str[$i+1];
$i++;
if(isset($pinyins[$c])){
if($ishead==0) $restr .= $pinyins[$c];
else $restr .= $pinyins[$c][0];
}else $restr .= "_";
}else if( eregi("[a-z0-9]",$str[$i]) ){ $restr .= $str[$i]; }
else{ $restr .= "_"; }
}
if($isclose==0) unset($pinyins);
return $restr;
}
if($_GET['hanzi'])
{
echo $pinyin=GetPinyin($_GET['hanzi'],1,0);
//echo "获得的拼音是:".$pinyin;
}
?>
把附件改名成pinyin.db
把附件改名成pinyin.db
程序及汉字库
$pinyins = Array();
//获取一串中文字符的拼音 ishead=0 时,输出全拼音 ishead=1时,输出拼音首字母
function GetPinyin($str,$ishead=0,$isclose=1){
global $pinyins;
$restr = "";
$str = trim($str);
$slen = strlen($str);
if($slen<2) return $str;
if(count($pinyins)==0){
$fp = fopen("./pinyin.db","r");
while(!feof($fp)){
$line = trim(fgets($fp));
$pinyins[$line[0].$line[1]] = substr($line,3,strlen($line)-3);
}
fclose($fp);
}
for($i=0;$i<$slen;$i++){
if(ord($str[$i])>0x80)
{
$c = $str[$i].$str[$i+1];
$i++;
if(isset($pinyins[$c])){
if($ishead==0) $restr .= $pinyins[$c];
else $restr .= $pinyins[$c][0];
}else $restr .= "_";
}else if( eregi("[a-z0-9]",$str[$i]) ){ $restr .= $str[$i]; }
else{ $restr .= "_"; }
}
if($isclose==0) unset($pinyins);
return $restr;
}
if($_GET['hanzi'])
{
echo $pinyin=GetPinyin($_GET['hanzi'],1,0);
//echo "获得的拼音是:".$pinyin;
}
?>
把附件改名成pinyin.db
把附件改名成pinyin.db
程序及汉字库
- php 输入汉字,查出对应的拼音
- 实现输入【汉字】自动识别出对应的【拼音】
- asp输入汉字取得汉字的拼音
- Silverlight combobox,实现输入拼音显示对应的所有的汉字
- 拼音对应汉字
- 汉字转拼音,用户表增加拼音字段,并将汉字姓名对应的拼音赋值给拼音字段
- 输入汉字返回每个汉字拼音的头一个…
- 汉字得出对应的拼音;通过拼音查找map中的汉字,逆向map多个装成list
- PHP汉字转拼音的函数
- PHP汉字转拼音的类
- PHP汉字转拼音的函数
- php 汉字转化成拼音的方法
- PHP汉字转换拼音的类
- PHP汉字转换拼音的类
- php获取汉字拼音首字母的函数
- PHP汉字转换拼音的函数代码
- php获取汉字拼音首字母的方法
- 一个比较齐全的汉字字库对应拼音 操作实现
- 搜索引擎爬虫访问权限规则:robots.txt介绍
- MySQL Replace INTO的使用
- 教你如何禁用Windows错误报告工具Dw20.exe
- dw20
- SQL SERVER 与ACCESS、EXCEL的数据转换
- php 输入汉字,查出对应的拼音
- (引)sizeof终极无惑
- php显示一个目录中的文件
- 调试方法和技巧
- ASP.NET动态生成HTML页面
- 用C#调用Windows API和其它进程通信
- php解决在线视频转换的问题
- sql脚本
- JS与XML结合用法