一只牛の窝

生命只是在演绎着自己的精彩,分享才是最大的快乐……

« PHP根据不同域名301跳转指定网址表单定义编码,搜索框定义搜索结果编码 »

dedecms内容页{dedefield.body}里关键词批量替换

dedecms内容页{dedefield.body}里关键词批量替换

{dede:field.body runphp='yes'}
$str = @me;
$str1 = array("链接","使用","百度");
$str2 = array("<a href='http://www.baidu.com'>链接</a>","<a href='http://www.baidu.com'>使用</a>","<a href='http://www.baidu.com'>百度</a>");
$str3 = str_replace($str1,$str2,$str);
@me = $str3;
 {/dede:field.body}


这个方法适合少量几个关键词的替换


下面的适合N个关键词的替换
引用的txt文件里的写法:

链接|<a href='http://www.baidu.com'>链接</a>
右键|22222


模板放下面代码:

{dede:field.body runphp='yes'}
$rs = file_get_contents("http://com.dede.com/t.txt");
$arr = explode("\r\n",$rs);
foreach($arr as $r){
list($a,$b)=explode('|',$r);
@me = str_replace($a,$b,"@me");
}
 {/dede:field.body}



原创文章如转载,请注明:转载自 阳春一月 [ http://blog.ycjan.com/ ]

本文链接地址:http://blog.ycjan.com/zonghe/201101222249.html

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

Powered By Z-Blog 1.8 Arwen Build 81206

Copyright ycjan.com 粤ICP备08002314号