php通过拼音首字母查询数据mssql(高效版)

<?php
class pysql{
//按拼音检索
function GetHanziScope($pinyin){
$py=strtolower ($pinyin);
$hz=array();
for ($i = 0; $i < strlen($py); $i++) {
$index = substr($py,$i,1);
if($index == "a"){$hz[$i][0] = "吖";$hz[$i][1] = "驁";}
else if($index == "b"){$hz[$i][0] = "八";$hz[$i][1] = "簿";}
else if($index == "c"){$hz[$i][0] = "嚓";$hz[$i][1] = "錯";}
else if($index == "d"){$hz[$i][0] = "咑";$hz[$i][1] = "鵽";}
else if($index == "e"){$hz[$i][0] = "妸";$hz[$i][1] = "樲";}
else if($index == "f"){$hz[$i][0] = "发";$hz[$i][1] = "猤";}
else if($index == "g"){$hz[$i][0] = "旮";$hz[$i][1] = "腂";}
else if($index == "h"){$hz[$i][0] = "妎";$hz[$i][1] = "夻";}
else if($index == "j"){$hz[$i][0] = "丌";$hz[$i][1] = "攈";}
else if($index == "k"){$hz[$i][0] = "咔";$hz[$i][1] = "穒";}
else if($index == "l"){$hz[$i][0] = "垃";$hz[$i][1] = "鱳";}
else if($index == "m"){$hz[$i][0] = "嘸";$hz[$i][1] = "椧";}
else if($index == "n"){$hz[$i][0] = "拏";$hz[$i][1] = "桛";}
else if($index == "o"){$hz[$i][0] = "噢";$hz[$i][1] = "漚";}
else if($index == "p"){$hz[$i][0] = "妑";$hz[$i][1] = "曝";}
else if($index == "q"){$hz[$i][0] = "七";$hz[$i][1] = "裠";}
else if($index == "r"){$hz[$i][0] = "亽";$hz[$i][1] = "鶸";}
else if($index == "s"){$hz[$i][0] = "仨";$hz[$i][1] = "蜶";}
else if($index == "t"){$hz[$i][0] = "他";$hz[$i][1] = "籜";}
else if($index == "w"){$hz[$i][0] = "屲";$hz[$i][1] = "鶩";}
else if($index == "x"){$hz[$i][0] = "夕";$hz[$i][1] = "鑂";}
else if($index == "y"){$hz[$i][0] = "丫";$hz[$i][1] = "韻";}
else if($index == "z"){$hz[$i][0] = "帀";$hz[$i][1] = "咗";}
else {$hz[$i][0] = $index;$hz[$i][1] = $index;}
}
return $hz;
}
//按拼音检索
function GetPinyinWhereString($fieldName,$pinyin){
$pinyin_arr=$this->GetHanziScope($pinyin);
//print_r($pinyin_arr);
$whereString='(';
for ($i = 0; $i < count($pinyin_arr); $i++) {
$whereString .= "(SUBSTRING(" . $fieldName . ", " . ($i + 1) . ", 1) >= '" . $pinyin_arr[$i][0] . "' AND SUBSTRING(" . $fieldName . ", " . ($i + 1) . ", 1) <= '" . $pinyin_arr[$i][1] . "') AND ";
}
if(substr($whereString,strlen($whereString)-4,4)=='AND '){
$whereString=substr($whereString,0,strlen($whereString)-4);
}
return $whereString.')';
}
}

转载于:https://www.cnblogs.com/foxtk/archive/2013/05/03/3057135.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值