今天给各位分享php按首字母搜索怎么做的知识,其中也会对php按首字母搜索怎么做的进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录:
- 1、PHP 首字母检索筛选怎么做 《A B C D。。。。。。。》 这样的 然后从数据库中把对应的中文 调出来 怎么做
- 2、求php获取首字母方法
- 3、[php教程]如何用PHP实现取字符的首字母?
- 4、PHP 根据汉字拼音搜索是怎么做到的
PHP 首字母检索筛选怎么做 《A B C D。。。。。。。》 这样的 然后从数据库中把对应的中文 调出来 怎么做
在保存到数据库时就需要拿出一个字段来保存首字母,至于怎么得到汉字的首字母。你可以找一下程序。我手里正好没有
求php获取首字母方法
function ($str){
$s1 = iconv('UTF-8','gb2312',$str);
$s2 = iconv('gb2312','UTF-8',$s1);
$s = $s2 == $str ? $s1 : $str;
$asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
if($asc = -20319 $asc = -20284) return 'a';
if($asc = -20283 $asc = -19776) return 'b';
if($asc = -19775 $asc = -19219) return 'c';
if($asc = -19218 $asc = -18711) return 'd';
if($asc = -18710 $asc = -18527) return 'e';
if($asc = -18526 $asc = -18240) return 'f';
if($asc = -18239 $asc = -17923) return 'g';
if($asc = -17922 $asc = -17418) return 'h';
if($asc = -17417 $asc = -16475) return 'j';
if($asc = -16474 $asc = -16213) return 'k';
if($asc = -16212 $asc = -15641) return 'l';
if($asc = -15640 $asc = -15166) return 'm';
if($asc = -15165 $asc = -14923) return 'n';
if($asc = -14922 $asc = -14915) return 'o';
if($asc = -14914 $asc = -14631) return 'p';
if($asc = -14630 $asc = -14150) return 'q';
if($asc = -14149 $asc = -14091) return 'r';
if($asc = -14090 $asc = -13319) return 's';
if($asc = -13318 $asc = -12839) return 't';
if($asc = -12838 $asc = -12557) return 'w';
if($asc = -12556 $asc = -11848) return 'x';
if($asc = -11847 $asc = -11056) return 'y';
if($asc = -11055 $asc = -10247) return 'z';
return null;
};
这是一个传入汉字,通过汉字的ASCII码来判断汉字的首字母的方法。已经调试,可以直接使用。望测试。
[php教程]如何用PHP实现取字符的首字母?
?php
function getfirstchar($s0){
$c=ereg('[a-zA-Z]', strtoupper(substr( $s0, 0, 1 )));
if($c){
return strtoupper(substr( $s0, 0, 1 )) ;
}else{
if($fchar=ord("a") and $fchar=ord("Z") )return strtoupper($s0{0});
if(is_numeric(substr( $s0, 0, 1 ))){
$s0 =ToChinaseNum (substr( $s0, 0, 1 ));
}
$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=-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 ToChinaseNum($num)
{
$char = array("零","一","二","三","四","五","六","七","八","九");
$dw = array("","十","百","千","万","亿","兆");
$retval = "";
$proZero = false;
for($i = 0;$i strlen($num);$i++)
{
if($i 0) $temp = (int)(($num % pow (10,$i+1)) / pow (10,$i));
else $temp = (int)($num % pow (10,1));
if($proZero == true $temp == 0) continue;
if($temp == 0) $proZero = true;
else $proZero = false;
if($proZero)
{
if($retval == "") continue;
$retval = $char[$temp].$retval;
}
else $retval = $char[$temp].$dw[$i].$retval;
}
if($retval == "一十") $retval = "十";
return $retval;
}
var_dump(getfirstchar("89ssss"));
?
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按首字母搜索怎么做的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于php按首字母搜索怎么做的、php按首字母搜索怎么做的信息别忘了在本站进行查找喔。