UPDATE a table to erase a long string of html

I’m fixing a friends wordpress site, and I’ve discovered that his previous malware infection added a long string of html to the end of hundreds of posts. This is the html:

<div style="position:absolute;filter:alpha(opacity=0);opacity:0.001;z-index:10;">
<a href="http://...">...</a></div>

I can write an UPDATE SET REPLACE for small strings. But I can’t figure out how it’s possible to find this exact string, given all the html and quotation marks. Is this at all possible?

Related posts

1 comment

  1. Here is my updated query:

    UPDATE posts
    SET post = SUBSTRING(post, 1, INSTR(post, '<div style="%position:absolute;') - 1)
    WHERE post LIKE '%<div style="%position:absolute;%'
    

    It replaces each post which contains the substring <div style="%position:absolute; with the substring of that post beginning at the first character and ending with the last character before the start of the garbage added at the end.

    This should work under the assumption that the garbage html always appears at the end, and that <div style="%position:absolute; only appears as the garbage text and is never part of an actual post.

Comments are closed.