在織夢(即dedecms)二次開發以及網站建設時,我們經常會用到字符串截取的問題,在織夢中字符串內容截取函數比較常用的有兩個。
Html2text() 函數是去掉html標簽代碼。
cn_substr(str,80) 函數是截取字符串長度。
當然,他們也可以合并起來使用:
[field:body function="cn_substr(Html2text(@me),80)"/]
更多函數總結:
基本語法:
函數一: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標簽元素,轉為純文本!