【问题标题】:How to Ignore certain tags and replace texts in PHP如何忽略某些标签并替换 PHP 中的文本
【发布时间】:2010-06-11 06:08:05
【问题描述】:

我有一个类似的变量

$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' 都会被删除。但不应删除&lt;script&gt; 标记中的'a'。

或者除了这个方法还有什么方法可以替换文字

请帮忙。

【问题讨论】:

    标签: php str-replace


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      【讨论】:

      • 也许——他不想去除嵌套标签(即脚本中的锚点),但如果他想去除“除
      • 我不想去掉任何标签。当我使用 str_replace(' ; ', '', $content);
      猜你喜欢
      • 1970-01-01
      • 2014-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-12
      • 2012-03-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多