-2

I have just discovered around a thousands posts on our site with hidden links. They are all contained in divs the styles like this:

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

The width and height are all different, the only identifier is the overflow:hidden

Here is one example

<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>

How do I create a RegEx that finds every day with the style that contains overflow:hidden then any character, set of character etc up until the closing div.

I tried this, but didn't work

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

I think it's due to not escaping the normal HTML.

I'm a RegEx noob.

Thanks Ollie

  • Actually escaping it [does work](https://regex101.com/r/4b8ndg/1) (be sure to use the "single line" mode), but [I recommend you to use an HTML parser because this is subject to a lot of possible errors](https://stackoverflow.com/a/1732454/4607733). – logi-kal Jan 19 '19 at 17:11

1 Answers1

0

Thanks mate, very detailed response :)

As you say it's sketchy, worked on some posts and not others.

We solved this by adding this to the functions.php file to strip all the problematic divs out server side.

RegEx was the incorrect approach.

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');

?>