php

位置:IT落伍者 >> php >> 浏览文章

php批量获取首字母(汉字、数字、英文)


发布日期:2023年07月19日
 
php批量获取首字母(汉字、数字、英文)

php批量获取首字母(汉字数字英文)

$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($titleutf);

}else if(ord($title)>= and ord($title)<=){ //大写英文开头

echo $letter=iconv_substr($titleutf);

}else if(ord($title)>= and ord($title)<=){ //小写英文开头

echo $letter=iconv_substr($titleutf);

}

}

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;

}

               

上一篇:解析php php

下一篇:浅析PHP中的字符串编码转换(自动识别原编码)