php批量获取首字母(汉字、数字、英文)的代码
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Libérer: 2016-07-25 09:03:40
original
864 Les gens l'ont consulté
-
-
$mysql_server_name='127.0.0.1'; //改成自己的mysql数据库服务器
- $mysql_username='用户'; //改成自己的mysql数据库用户名
- $mysql_password='密码'; //改成自己的mysql数据库密码
- $mysql_database='数据库'; //改成自己的mysql数据库名
- mysql_connect('127.0.0.1', $mysql_username,$mysql_password) or die('database not access');
- mysql_select_db($mysql_database);
- mysql_query("SET NAMES 'utf8'");
- $equery2 = " select title from 表1 ";
- $result2=mysql_query($equery2);
while ($row = mysql_fetch_array($result2, MYSQL_BOTH))
- {
- $title=$row["title"];
- if (ord($title)>128) { //汉字开头
- echo $letter=getfirstchar($title);
- }else if(ord($title)>=48 and ord($title)echo $letter=iconv_substr($title,0,1,'utf-8');
- }else if(ord($title)>=65 and ord($title)echo $letter=iconv_substr($title,0,1,'utf-8');
- }else if(ord($title)>=97 and ord($title)echo $letter=iconv_substr($title,0,1,'utf-8');
- }
- }
function getfirstchar($s0){
- $s=iconv("UTF-8","gb2312", $s0);
- $asc=ord($s{0})*256+ord($s伊雪)-65536;
- if($asc>=-20319 and $ascif($asc>=-20283 and $ascif($asc>=-19775 and $ascif($asc>=-19218 and $ascif($asc>=-18710 and $ascif($asc>=-18526 and $ascif($asc>=-18239 and $ascif($asc>=-17922 and $ascif($asc>=-17417 and $ascif($asc>=-16474 and $ascif($asc>=-16212 and $ascif($asc>=-15640 and $ascif($asc>=-15165 and $ascif($asc>=-14922 and $ascif($asc>=-14914 and $ascif($asc>=-14630 and $ascif($asc>=-14149 and $ascif($asc>=-14090 and $ascif($asc>=-13318 and $ascif($asc>=-12838 and $ascif($asc>=-12556 and $ascif($asc>=-11847 and $ascif($asc>=-11055 and $ascreturn false;
- }
- ?>
-
复制代码
|
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Derniers articles par auteur
-
2025-02-26 03:58:14
-
2025-02-26 03:38:10
-
2025-02-26 03:17:10
-
2025-02-26 02:49:09
-
2025-02-26 01:08:13
-
2025-02-26 00:46:10
-
2025-02-25 23:42:08
-
2025-02-25 22:50:13
-
2025-02-25 21:54:11
-
2025-02-25 20:45:11
Derniers numéros
-
2025-03-21 13:39:34
-
2025-03-21 13:38:34
-
2025-03-21 13:37:19
-
2025-03-21 13:35:24
-
2025-03-21 13:34:32