【发布时间】:2012-11-02 17:23:05
【问题描述】:
您好,我想删除一个 img 标签,它的 src 是使用 preg_replace 的内容中的一个 url
例如。
$content = "<center><img src="http://example.net/wp-content/uploads/2012/10/cell-degeneration-contn.jpg" alt="" title="cell-degeneration-contn" width="950" height="272" class="alignnone size-full wp-image-100" /></center><h2>A first-in-class approach to stop & reverse </h2>";
所以输出将是:
$content="<center></center><h2>A first-in-class approach to stop & reverse </h2>";
但如果可能的话,最好的输出是:
$content="A first-in-class approach to stop & reverse ";
【问题讨论】:
-
是否有可以使用 preg_replace?
-
欢迎堆栈溢出。正如 Marc B 指出的那样,正则表达式似乎不是操作 html 文本的方式;只是澄清你是否真的需要 preg_replace