Php 使用preg_replace删除不需要的链接

Php 使用preg_replace删除不需要的链接,php,parsing,preg-replace,Php,Parsing,Preg Replace,我正在尝试删除类似这样的内容: <a href="http://women.domain.com">women.domain.com</a> 我想应该是: $this->tresc[$i][description]=preg_replace("/\<a(.*)href=(\"|')http:\/\/women\.domain\.com.*(\"|')(.*)\/\>/i", "",$this->tresc[$i][description]);

我正在尝试删除类似这样的内容:

<a href="http://women.domain.com">women.domain.com</a>

我想应该是:

$this->tresc[$i][description]=preg_replace("/\<a(.*)href=(\"|')http:\/\/women\.domain\.com.*(\"|')(.*)\/\>/i", "",$this->tresc[$i][description]);
$this->tresc[$i][description]=preg\u replace(“/\
$this->tresc[$i][description]=preg\u replace(“/\.*\/i”,”,$this->tresc[$i][description]);
$pattern='(\”;
var_dump(preg_replace($pattern,“,$string));//打印“string”click(长度=6)
$this->tresc[$i][description]=preg_replace(“//i”,”,$this->tresc[$i][description]);
$this->tresc[$i][description]=preg_replace(“//i”,”,$this->tresc[$i][description]);

this:preg_replace(“//”、“hello”、$this->tresc[$i][description]);首先,您必须通过添加UAN来取消正则表达式的reedy,然后您必须更正正则表达式的尾部,以便识别img标记中缺少的。这就是您所要做的。请不要在StackOverflow上问此类问题。您真的不想使用正则表达式解析/操作DOM。如果文档是偶数格式稍有错误,或者您没有考虑到所有的可能性,它将失败。REGEX不是解析器;PHP有一些非常好的DOM功能。@Spacedust这是删除链接的一个示例。我用了一种较短的方法。请参见下文;)
$this->tresc[$i][description]=preg_replace("/\<img(.*)src=(\"|')http:\/\/women\.domain\.com.*(\"|')(.*)\/\>/i", "",$this->tresc[$i][description]);
$this->tresc[$i][description]=preg_replace("/\<a .*\>.*\<\/a\>/i", "", $this->tresc[$i][description]);
$pattern = '(\<a href=["|\']+[http(s)?:\/\/]+([a-z0-9\-]+[.]){1,}+[a-z]{2,4}+[\/]+(.*)+["|\']\>+(.*)+\</a\>)';
$string = "click <a href='http://subdomain.sitename.tld/somedir'>here</a>";

var_dump(preg_replace($pattern, "", $string)); // prints "string 'click ' (length=6)"
$this->tresc[$i][description]=preg_replace("/<a href=\"(.*)\">/i", "",$this->tresc[$i][description]);
$this->tresc[$i][description]=preg_replace("/<\/a\>/i", "",$this->tresc[$i][description]);