Home > php教程 > php手册 > body text

Dedecms常用函数解析

WBOY
Release: 2016-06-13 12:30:03
Original
865 people have browsed it

大家都知道,dedecms支持[field:senddate function=”strftime('%y-%m-%d %H:%M',@me)”/]这样的一些用法,即标记内使用function,调用相关的函数对当前标签返回的内容进行再次处理再显示出来。

       就拿上面这个标记为例子,本来程序显示数据库某个表的字段senddate,但通过查看数据库发现,senddate只是一大串数字,并不是我们想要的时间格式,PHP语言本身对时间处理是有一些自带的函数,strftime就是php本身自带的函数,当然你也可以扩展,自己编写自己的函数,模板上我们不需要显示这些数字,我们需要按照一定格式转换为我们的时间,这时候就可以使用这个函数进行处理了。


        下面我们来分析下dedecms自带一些常用函数的使用方法:

■GetCurUrl()

这个估计用到的不是太多,这个函数获得当前运行的脚本地址,使用时候可以通过下列方式:
{dede:CurUrl runphp='yes'}
@me = GetCurUrl();
{/dede:CurUrl}

■GetAlabNum()

返回半角数字的,如果你某个字段信息不希望出现全角数字,可以使用这个函数,例如:
[field:listnum/]返回的是12234,我希望是半角数字12234,可以这样使用函数:
[field:listnum function=”GetAlabNum(@me)”/]

■Text2Html()

文本转HTML,函数将文本内容中的空格、…等字符转换为HTML标记,可以这样使用:
[field:textcontent function=”Text2Html(@me)”/]
同样这里也有个相反的函数,将html转换为Text的,Html2Text(),其用法类似

■ClearHtml()

清除html标记,函数将内容中包含的html标记清除。用法:
[field:content function=”ClearHtml(@me)”/]

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!