如何忽略某些标签并替换PHP中的文本

时间:2010-06-11 06:08:06

标签: php str-replace

我有一个像

这样的变量
$content = "Lorem Ipsum is simply <b>dummy text of the printing</b> and typesetting industry.
 Lorem Ipsum has been the industry's <i>standard dummy text</i> ever since the 1500s 
<string>javascriptFunc();</script>" ;

当我使用str_replace('a', '', $content);所有'a'被删除时。但不应删除<script>标记内的'a'。

或者有没有办法替换此方法以外的文字

请帮忙。

2 个答案:

答案 0 :(得分:2)

使用HTML DOM parser获取标记内的文本,然后对结果运行str_replace()函数。

答案 1 :(得分:0)

相关问题