php函数str_replace的使用方法总结
作者:admin 日期:2012-10-20
字符串取代。
语法: string str_replace(string needle, string str, string haystack);
返回值: 字符串
函数种类: 资料处理
使用范例
下例将 %body% 以 black 取代
- $bodytag = str_replace("%body%", "black", "<body text=%body%>");
- echo $bodytag;
格式:
[@str_replace("要替换的旧内容", "要取代原内容的新字符", $被替换内容的变量名)]
[@str_replace(array('旧1','旧2','旧3'), array('新1','新2','新3'), $被替换内容的变量名)]
[@str_replace(array('旧1','旧2','旧3'), '新内容', $被替换内容的变量名)]
实例:
多对一替换:想把内容字段里所有的<p></p>标签清除掉,替换成空
[@str_replace(array('<p>','</p>'), '', $Content)]
一对一替换:想把内容字段里所有的<br>标签换成<p>
[@str_replace('<br>', '<p>', $Content)]
多对多替换:想把内容字段里的<br>换成<br />, 同时<p>换<hr>,把</p>全清除[@str_replace(array('<br>', '<p>'),array('<br />', '<hr>'), $Content)]
广告位