$mysql_server_name= ; //改成自己的mysql数据库服务器
$mysql_username= 用户 ; //改成自己的mysql数据库用户名
$mysql_password= 密码 ; //改成自己的mysql数据库密码
$mysql_database= 数据库 ; //改成自己的mysql数据库名
mysql_connect( $mysql_username $mysql_password) or die( database not access );
mysql_select_db($mysql_database);
mysql_query("SET NAMES utf ");
$equery = " select title from 表 ";
$result =mysql_query($equery );
while ($row = mysql_fetch_array($result MYSQL_BOTH))
{
$title=$row["title"];
if (ord($title)> ) { //汉字开头
echo $letter=getfirstchar($title);
}else if(ord($title)>= and ord($title)<= ){ //数字开头
echo $letter=iconv_substr($title utf );
}else if(ord($title)>= and ord($title)<= ){ //大写英文开头
echo $letter=iconv_substr($title utf );
}else if(ord($title)>= and ord($title)<= ){ //小写英文开头
echo $letter=iconv_substr($title utf );
}
}
function getfirstchar($s ){
$s=iconv("UTF " "gb " $s );
$asc=ord($s{ }) +ord($s{ }) ;
if($asc>= and $asc<= )return "A";
if($asc>= and $asc<= )return "B"; if($asc>= and $asc<= )return "C";
if($asc>= and $asc<= )return "D";
if($asc>= and $asc<= )return "E";
if($asc>= and $asc<= )return "F";
if($asc>= and $asc<= )return "G";
if($asc>= and $asc<= )return "H";
if($asc>= and $asc<= )return "J";
if($asc>= and $asc<= )return "K";
if($asc>= and $asc<= )return "L";
if($asc>= and $asc<= )return "M";
if($asc>= and $asc<= )return "N";
if($asc>= and $asc<= )return "O";
if($asc>= and $asc<= )return "P";
if($asc>= and $asc<= )return "Q";
if($asc>= and $asc<= )return "R";
if($asc>= and $asc<= )return "S";
if($asc>= and $asc<= )return "T";
if($asc>= and $asc<= )return "W";
if($asc>= and $asc<= )return "X";
if($asc>= and $asc<= )return "Y";
if($asc>= and $asc<= )return "Z";
return false;
lishixinzhi/Article/program/PHP/201311/20913
根数据库系统的算法有关,早期版本的算法是自然的多个线程二分法,那个线程先查到满足条件的数据就先输出出来,这样就是乱序的,后期经过改进按照主键自然排序输出。
如果order by的值相同,一般是按自然排序,就是首个字符的字母或汉字的发音的首字母的排序。
以上就是关于php批量获取首字母(汉字、数字、英文)全部的内容,包括:php批量获取首字母(汉字、数字、英文)、mysql 默认排序问题、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)