• 微信号:Zh-y9213
您当前的位置:爱资源分享网 > > 网站源码 > 教程合集

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

栏目:教程合集时间:2022-06-22 18:48阅读数:43人阅读

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)'/]
 
套路很深,不支持下载!

本站所有文章、数据、图片均来自互联网,一切版权均归源网站或源作者所有。

如果侵犯了你的权益请来信告知我们删除。邮箱:737597453@qq.com