首頁  >  文章  >  後端開發  >  php批次取得首字母(漢字、數字、英文)_PHP教學

php批次取得首字母(漢字、數字、英文)_PHP教學

WBOY
WBOY原創
2016-07-22 09:02:35838瀏覽

  php批次取得首字母(漢字、數字、英文)

  $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{1})-65536;

  if($asc>=-20319 and $asc

  if($asc>=-20283 and $asc=-19775 and $asc

  if($asc>=-19218 and $asc

  if($asc>=-18710 and $asc

  if($asc>=-18526 and $asc

  if($asc>=-18239 and $asc

  if($asc>=-17922 and $asc

  if($asc>=-17417 and $asc

  if($asc>=-16474 and $asc

  if($asc>=-16212 and $asc

  if($asc>=-15640 and $asc

  if($asc>=-15165 and $asc

  if($asc>=-14922 and $asc

  if($asc>=-14914 and $asc

  if($asc>=-14630 and $asc

  if($asc>=-14149 and $asc

  if($asc>=-14090 and $asc

  if($asc>=-13318 and $asc

  if($asc>=-12838 and $asc

  if($asc>=-12556 and $asc

  if($asc>=-11847 and $asc

  if($asc>=-11055 and $asc

  return false;

  }

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/371854.htmlTechArticlephp批次取得首字母(漢字、數字、英文) $mysql_server_name='127.0.0.1'; //改成自己的mysql資料庫伺服器$mysql_username='用戶'; //改成自己的mysql資料庫用...
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn