替换某些<;a href=certific.domain.com..带有php preg_replace


Replacing certain <a href..certain.domain.com... with php preg_replace

所以,我有一个文本字符串:

string with a bunch of links but i need to simply get rid of these <a href="a.domain.com">Title</a> string with more links and text

我需要使用PHP preg_replace从<a to a>中删除a.domain.com所在的所有内容(它始终是同一个域)
这看起来很简单,但我想不通<或找到任何解释regex:/

的地方

我一直喜欢这个regexp网站:http://www.regular-expressions.info/这不是一个完整的答案,但我只想匹配<a [...]>[...]</a>,并确保它不是贪婪的,这样你就不会从第一次出现<a [...]>一直到最后一次出现</a>。这是在另一个论坛上推荐的,你可能也想试一试:

$rev= preg_replace('/<a href="([^<]*)">([^<]*)<'/a>/', '', $_POST['rev']);

如果您想保留<a>标记中的内容,可以尝试strip_tags()函数。

如果你想要更复杂的东西,学习正则表达式的好教程是http://www.regular-expressions.info/

你可以试试

$no_tags = preg_replace('#<a (.*?)>(.*?)</a>#', '', $text);

但请注意,如果你的标签比你发布的例子更复杂,这将被打破。