Skip to main content
 Web开发网 » 站长学院 » 织梦教程

织梦DedeCMS模板标签调用str_replace()替换函数的方法

2020年09月12日7350百度已收录

str_replace() 函数:使用一个字符串替换字符串中的另一些字符。

 

举个例子:

 

 

[field:sitepath function='str_replace("{cmspath}","http://localhost/",@me)/]

 

实际上是查找内容中指定的部分然后进行替换,上面是DEDE中的应用方法,第2个双引号实际是替换的内容,这里是http://localhost/

 

上面标签的作用就是查找内容中的{cmspath}并替换为http://localhost/,实际上也就是去掉。

 

str_replace()还有一个参数count ,是替换的次数,语法为

 

 

str_replace(find,replace,string,count)

 

我们可以引申出很多应用方法了。

 

比如下面的标签都可以应用:

 

 

[field:info/]

[field:arcurl/]

[field:typedir/]

 

举个例子:

 

 

[field:title function='str_replace("aaa","bbb",@me)/]

[field:title function='str_replace("测试","test",@me)/]

 

查找标题中的aaa替换成bbb。

 

但下面这个比较常用,主要应用于二三级栏目嵌套调用中

 

 

[field:typedir function='str_replace("{cmspath}","",@me)'/]


 

评论列表暂无评论
发表评论
微信