Search the entire html document for an exact code & ldquo; & lt; br & gt; foo & lt; br & gt; & rdquo; and delete it

advertisements

I have a page which has exactly <br>foo<br> several times in different parts of its code

Example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Test</title>
  </head>

  <body>
    The quick brown <br>foo<br> fox jumped over the lazy <br>foo<br> dog.
  </body>
</html>

But I need the page to say:
The quick brown fox jumped over the lazy dog.

Rather than:
The quick brown
foo
fox jumped over the lazy
foo
dog.

I need it to keep deleting the <br>foo<br> even if I later add more text and more <br>foo<br>

Please provide a full functional code, hopefully php

Additional information:
I am loading much of the text through php includes.
I don't want to have to declare the original string in php, I want the php to check the html code and delete a specified string.


You can't do what you're asking with PHP unless the string is being output by PHP...

I suppose you could use javascript for this; for example (using JQuery):

$(document).ready(function(){
        var old_body = $('body').html();
        var new_body = old_body.replace(new RegExp("<br>foo<br>", "g"),'');
        $('body').html(new_body);
    });

However, it really would be better if you used one of the methods described already and pass the content through PHP.

Updated to actually work...