正则表达式,用于删除 a 中的所有垃圾邮件链接 <div> 唯一的标识符是溢出:隐藏



我刚刚在我们的网站上发现了大约数千条带有隐藏链接的帖子。它们都包含在div中,样式如下:

<div style='width:10px;height:13px;overflow:hidden'>
<div style='overflow:hidden;width:7px;height:13px'>

宽度和高度都不同,唯一的标识符是溢出:隐藏

以下是的一个例子

<div style='width:10px;height:13px;overflow:hidden'>
<p>BRANDO CHANGED WILL IN LAST DAYS.(News)</p>
<p>The Mirror (London, England) July 8, 2004 Byline: IAN MARKHAM-SMITH HOLLYWOOD legend Marlon Brando changed his will days before his death, it emerged last night.</p>
<p>Movie mogul Mike Medavoy revealed that before the eccentric 80-year-old succumbed to illness on Friday, he summoned lawyers and some friends to make significant changes to his estate. <a href="http://lastnightmovienow.net">lastnightmovienow.net last night movie</a></p>
</div>

我如何创建一个RegEx,用包含溢出的样式查找每天:隐藏然后任何字符,字符集等,直到结束div。

我试过了,但没有用

<div style='.*overflow:hidden'>(.*)</div>

我认为这是由于没有逃离正常的HTML。

我是RegEx的无名小卒。

谢谢奥利

谢谢伙计,非常详细的回复:)

正如你所说,这是粗略的,在一些帖子上工作过,而在其他帖子上没有。

我们通过将其添加到functions.php文件中来解决这个问题,从而从服务器端剥离所有有问题的div。

RegEx是错误的做法。

function my_the_content_filter( $content ) {
$content = preg_replace("#<div[^>]*overflow:hidden[^>]*>.*?</div>#is", "", $content);
return $content;
}
add_filter( 'the_content', 'my_the_content_filter');
?>

最新更新