【发布时间】:2014-05-06 21:42:12
【问题描述】:
如何用它的链接替换标签的内容
$str = 'This <strong>string</strong> contains a <a href="/local/link.html">local link</a>
and a <a href="http://remo.te/link.com">remote link</a>';
$str = strip_tags($str,'<a>'); // strip out the <strong> tag
$str = ?????? // how can I strip out the local link anchor tag, but leave the remote link?
echo $str;
期望的输出:
This string contains a local link and a <a href="http://remo.te/link.com">remote link</a>
或者,更好,用它的 url 替换远程链接的内容:
This string contains a local link and a http://remo.te/link.com
我怎样才能达到最终的输出?
【问题讨论】:
-
看起来你可能想学习一些正则表达式:)
-
@JayBlanchard,哈哈。我终于弄明白了。
标签: php replace preg-replace str-replace strip-tags