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)’/]
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。