您当前的位置: 主页 > 优化教程
方法一,织梦默认有这个函数,在include/inc/inc_fun_funAdmin.PHP中.即SpGetPinyin()
 
但他只能得到全拼,没法得到首字母,
 
用法举例
 
$pingyin=GetPinyin($row['title'],0,1); 
 
$a=substr(GetPinyin($row['title']),0,1);//得到拼音首字母 
 
 
方法二,如果你只想得到首字母,不需要全拼,还可以用以下函数得到首字母
 
if (ord($row['title'])>128) { //汉字开头 
 $letter=getfirstchar2($row['title']); 
}else if(ord($row['title'])>=48 and ord($row['title'])<=57){ //数字开头 
$letter=iconv_substr($title,0,1,'utf-8'); 
}
else if(ord($row['title'])>=65 and ord($row['title'])<=90){ //大写英文开头 
$letter=iconv_substr($row['title'],0,1,'utf-8'); 
}else if(ord($row['title'])>=97 and ord($row['title'])<=122){ //小写英文开头 
$letter=iconv_substr($row['title'],0,1,'utf-8'); 
$letter=strtoupper($letter);//字母转换成大写 
print_r($letter);exit; 
 function getfirstchar2($s0){ 
$s=iconv("UTF-8","gb2312", $s0);  
$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;  
}
 
三,如何实现文章列表中,按首字母进行归类归档排序?下面是完整代码
 
<div class="container padding-big"style="min-height:200px;"> 
<p>{dede:type }[field:typename/]{/dede:type}</p> 
<div> 
{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 `dede_arctype` tp on arc.typeid=tp.id where arc.typeid=2"; 
 $dsql->SetQuery($sql); 
$dsql->Execute();//执行SQL操作 
while($row = $dsql->GetArray()){ 
//print_r($row['title']);exit; 
//$pingyin=GetPinyin($row['title'],0,1); 
$letter=substr(GetPinyin($row['title']),0,1);//取得拼音首字母 
$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);//字母排序 
//print_r($arr);exit; 
$b=1; 
foreach($arr as $k=>$v){ 
  
//print_r($v);exit; 
echo '<div><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/><hr/>'; 
              
        }     
             echo '<br/></div>';// print_r($b%4); 
             if($b%3==0){echo '<hr></hr>';//hr{background:#ddd;color:#ddd;clear:both;float:none;width:100%;height:1px;margin:10px 0;
             border:none;-moz-box-sizing:content-box;box-sizing:content-box;}hr.space{background:#fff;color:#fff;visibility:hidden;}hr的css,强制换行,防止错位 
             } 
             $b++; 
             } 
{/dede:php} 
</div> 
</div>
 

关键词:织梦,获得,首,字母,方法,并,实现,文章,列表,    标签:
    更多资讯请收藏关注 网站模板(www.1yc.cn)

织梦限制会员每天投稿数量方法在php空间中建一个网站着实不容易。作为一站长、网站管理员,最烦恼的莫... 2021-08-14
织梦dedecms系统中英文网站之中英文搜索结果最近做的中英文版搜索时发现搜索不尽人意总是出现双语混搭模式:这样可以解... 2021-07-27
教程:dede输出织梦全站RSS文件的方法织梦后台默认生成更新RSS文件是按照网站栏目生成告诉用户每个栏目的RS... 2021-09-16
dedecms实现全文输入rss的操作方法之前小编写过关于rss的文章,但是没有写入到怎么进行操作以及改装他们,... 2021-07-30
详解织梦模板[field:global name=autoindex/]标签的使用有时候我们需要在dede:list或者dede:arclist里面为列... 2021-07-22
织梦源码程序如何增加自由列表的排序方式呢织梦程序很多功能系统默认的都是比较单一的,但是有的时候站长朋友们建站却... 2021-08-14
用SQL语句获取Dedecms v5.7每个栏目中的文章数量下面是代码在前台页面中的显示效果: 共有会员:72 名 本月更新:72... 2021-07-30
dedecms提取文章内容所有图片的一个笨办法由于在dedecms文章管理系统中,使用静态生成页里不能直接使用php... 2021-08-09
DedeCMS 会员空间“的空间”删除方法掉烦人的会员空间名称总有个的空间的办法 找到文件 /member/ed... 2021-07-22
织梦网站出现多图发布无法使用页面空白的原因昨天小编在使用织梦网站的时候遇到一个问题,在发布文章时,因为是使用了多... 2021-09-17
dedecmsDedeCMS会员登录或退出后直接跳转到首页的修改教程织梦DedeCMS会员在登录后会直接跳转到会员中心,退出也是一样,但是... 2021-08-09
如何修改DedeCms验证码的样式修改文件 验证码文件位置 include\validateimg.ph... 2021-07-30
dedecmsDEDECMS 如何调用随机数织梦DEDECMS 如何调用随机数 。 好了,什么是随即数字,很简单了... 2021-08-09
织梦禁止调用隐藏栏目下文章的方法在用 织梦模板 建站的过程中,涉及调用全站的最新文章时,DedeCMS... 2021-07-22
开启DedeCMS软件源码及分类信息采集功能的方法本文实例讲述了开启DedeCMS软件源码及分类信息采集功能的方法。分享... 2021-07-27
织梦关键词维护里面字数多的词优先字数少的词的解决办法织梦后台的关键词维护默认的情况是字数少的词优先于字数多的词,比如我们有... 2021-08-14
织梦DEDECMS首页列表页调用文章TAG标签的方法1.如果是dedecms v5.7版本直接使用标签 [field:id... 2021-07-27

线
咨询热线:
135-0038-3336
在线客服:
点击这里给我发消息
微信交流:
公司官网: www.1yc.cn