欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

dedecms模板中字符串截取的几种方法

shiping1 的头像

方法一:

{dede:arclist typeid=’9′ titlelen=’40′ orderby=” limit=’0,5′}<li><a href=”#” target=”_blank”>[field:title /]</a></li>{/dede:arclist}

说明:arclist,的详细参数说明在后台的模板里面有详细说明,具体可参考那里的介绍。其中:titlelen,可以截取字符串的个数,这里的意思是输出20个汉字

方法二:

{dede:arclist typeid=’9′ titlelen=’40′ orderby=” limit=’0,5′}<li><a href=”#” target=”_blank”>[field:title function="cn_substr(@me,10)"/]</a></li>{/dede:arclist}

说明:[field:title function="cn_substr(@me,10)"/],意思就是:截取字段 title 的前10个字符,即5个汉字

更多函数解析:

基本语法:函数一:function=cn_substr(@me,200)(功能:获取指定数值的字符串)函数二:function=html2text(@me)(功能:去掉html样式,转换为纯文本字符)函数三:function=GetDateTimeMk(‘@me’)(功能:根据秒数返回时间)函数四: function=“GetDateMK(@me) (功能:根据秒数返回日期)函数五: function=‘strftime(“%m-%d”,@me)’(功能:根据秒数返回格式化的日期或者时间,php自带的函数)首页: 08                                  [field:pubdate function=strftime('%d',@me)/] 08 日                             [field:pubdate function=strftime('%d日',@me)/] 06-08                            [field:pubdate function=strftime('%m-%d',@me)/] 06月08日                     [field:pubdate function=strftime('%m月%d日',@me)/] 09-06-08                      [field:pubdate function=strftime('%y-%m-%d',@me)/] 2009-06-08                 [field:pubdate function=strftime('%Y-%m-%d',@me)/] 09年06月08日            [field:pubdate function=strftime('%y年%m月%d日',@me)/] 2009年06月08日       [field:pubdate function=strftime('%Y年%m月%d日',@me)/] 2009-06-08  13:28    [field:pubdate function=strftime('%Y-%m-%d %H:%M',@me)/]列表页: [field:pubdate function="GetDateTimeMK(@me)"/]==2008-1-1 18:30:02 [field:pubdate function="GetDateMK(@me)"/]==2008-05-15 函数六: function=‘str_replace(“lit_”,“”,@me) (功能:替换字符串) 函数七: function=MyDate(‘m-d’,@me) (功能:返回格林威治标准时间) 组合函数:function="html2text(cn_substr('@me',200))"(功能:提取指定个数的字符串并去掉html样式,转换为纯文本字符)举例: {dede:field.content function="Html2Text(cn_substr('@me',110))" /}功能:获取栏目信息摘要信息(提取110个字符[55个汉字]),删除hml标签元素,转为纯文本!


来自 http://jingyan.baidu.com/article/0320e2c1f000771b86507b6b.html

普通分类: