很多站长朋友们都不太清楚php拼音模糊查询,今天小编就来给大家整理php拼音模糊查询,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 PHP 根据汉字拼音搜索是怎么做到的 2、 php+MYSQL模糊查找关键字的问题 3、 PHP模糊查询怎么实现? PHP 根据汉字拼音搜索是怎么做到的<?php
function getfirstchar($s0){ //获取单个汉字拼音首字母。注意:此处不要纠结。汉字拼音是没有以U和V开头的
$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;
//return $s0;
}
function pinyin_long($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 pinyin_long('*《,@#$123HAHadf一年后');
?>
php+MYSQL模糊查找关键字的问题如果是通过姓名查找呢,我建议你还是把所有姓都定义好在查询吧(可以通过拼音索引增加软件友好度),这样查询的效率会好很多,总比每次都要把姓名从数据库里拿出来再抽象成模糊查询字段
再查询要快吧。
如果真是可以自己抽象出来所有符合的模糊对象的话,我看快赶上人工智能了,计算量不小。现阶段应该还用不到。用到了,我们也做不出来。
不知道对你有用吗,第二次回答问题。
O(∩_∩)O哈哈~
PHP模糊查询怎么实现?1.请注意php中的变量,始终以 $ 开头,你有好几处都没写正确
2.你连接和查询用的mysqli,获取行用了mysql_fetch_row,这是不对应的,而且 mysql_fetch_row是函数,你只写了个名字,是调用错误
3.根据报错页面,你连接mysql的用户名和密码是错误的,可能你没弄清楚用法随便填的吧
$connect = mysqli_connect('localhost',
'mysql用户名,开发用的一般是root',
'用户名对应的密码',
'要连接的数据库');
4.mysqli库不同于mysql库,mysql连接上之后,使用查询或其它函数,会自动调用之前的连接资源,mysqli需要手动传入连接对象
mysql_query(' SELECT * FROM text_table limit 10 ');
mysqli_query($connect, ' SELECT * FROM text_table limit 10 ');
5.如果需要判断有查询关键字才搜索,那就把if放在外面,不然你这里没关键字,数据库查询操作都会执行,只不过没获取结果集而已
if(!empty($keyword)){
$conn = mysqli_connect( ... );
if (mysqli_connect_errno()) {
printf("连接失败: %s\n", mysqli_connect_error());
exit();
}
$keyword = addslashes($keyword);
$sql = "SELECT * FROM user where username LIKE '%$keyword%'";
$result = mysqli_query($conn,$sql);
$user = array();
while ($row = mysqli_fetch_assoc($result))
{
$user[]=$row;
}
mysqli_free_result($result);
mysqli_close($conn);
}
关于php拼音模糊查询的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。
查看更多关于php拼音模糊查询 php模糊搜索功能的详细内容...