Method One, the dream of weaving by default has this function, in include/inc/inc_fun_funadmin.php. That is, Spgetpinyin ()
But he can only get the whole spell, can't get the first letter, it should be a bug. If you want to call this function on the whole station, it is suggested to copy this function to the include/extend.func.php file, which can be called at the whole station.
Examples of usage
$pingyin =spgetpinyin ($row [' title '],0,1), $a =substr (Spgetpinyin ($row [' title ']), 0, 1);//Get pinyin Initials
Method Two, if you only want to get the first letter, do not need to complete the spelling, you can also use the following function to get the first letter
if (Ord ($row [' title ']) >128) { //Chinese character opening $letter =getfirstchar2 ($row [' title ']);} Else if (Ord ($row [' title ']) >=48 and ord ($row [' title ']) <=57) { //digit start $letter = Iconv_substr ($title, 0,1, ' utf-8 ');} Else if (Ord ($row [' title ']) >=65 and ord ($row [' title ']) <=90) { //Capital English opening $letter=iconv_ substr ($row [' title '],0,1, ' utf-8 ');} Else if (Ord ($row [' title ']) >=97 and ord ($row [' title ']) <=122) { //lowercase english start $letter = Iconv_substr ($row [' title '],0,1, ' utf-8 '); $letter =strtoupper ($letter);//letters converted to uppercase}print_r ($letter);exit; Function getfirstchar2 ($s 0) {$s =iconv ("UTF-8", "gb2312", $s 0); $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 false; }
Third, how to implement the article list, according to the first letter classification archive sorting? Here is the complete code
<div class= "Container padding-big" style= "min-height:200px;" ><p class= "Text-large" >{dede:type }[field:typename/]{/dede:type}</p><div class= "Line-big" >{dede:php} $sql = "Select arc.id,arc.writer,arc.typeid, arc.title , arc.senddate,tp.sitepath,tp.namerule,tp.typedir from dede_archives arc left join ' #@__arctype ' tp on arc.typeid=tp.id where arc.typeid=2 "; $ Dsql->setquery ($sql); $dsql->execute ();//Execute SQL Operation while ($row = $dsql->getarray ()) {//print_r ($ row[' title '); exit;//$pingyin =spgetpinyin ($row [' title '],0,1); $letter =substr (Spgetpinyin ($row [' title ']), 0, 1);// obtained pinyin initials $letter=strtoupper ($letter), $arr [$letter] [writer '][]= $row ["Writer"]; $arr [$letter] [' URL '][]=getfileurl ( $row [' id '], $row [' typeid '], $row [' senddate '], $row [' title '],0,0, $row [' Namerule '], $row [' Typedir '],0, ', 0, ', $row [' SitePath ']), $arr [$letter] [title '][]= $row ["title"]; } ksort ($arr);//Alphabetical sort//print_r ($arr); exit; $b =1;foreach ($arr as $k = $v) {//print_r ($v);exit;echo ' <div class= "x3" ><p class= " Padding-left bg-eee st ">". Strtoupper ($k). ' </p> ';for ($x =0; $x <count ($v [' title ']); $x + +) { echo ' <a href= ' '. $v [url][$x]. ' " ><strong> ' . $v [title][$x]. ' </strong></a><br/>
Dedecms to get the first letter or Pinyin method, and to achieve a list of articles by the first letter classification