0

I need to remove the content between those html blocks:

$var1 ="

    <html><head>
    <meta http-equiv='content-type' content='text/html; charset=ISO-8859-1'></head><body>
    <img alt='shopozilla' src='http://www.ssopte.com/images/2010/usdos-logo-seal.png' >

    <span style='font-family: Arial,Helvetica,sans-serif; color: rgb(93, 93, 93);
    font-size: 17px; font-weight: bold;'>shopozilla sent this message to
";

$var2 = "

    Section 222 of the sand sAct. Section 222(f) provides that the     records of the separtment of State and of diplomatic and consular  </font><br>
    </td></tr></tbody></table></td></tr></tbody></table></body></html> 

";

So far I tried

<pre>
$content =  preg_replace("/$var1(.*)$var2/m", "", $htmlContent);
</pre>

but is not working so I need a pattern/regex which should work .

Andy Lester
  • 91,102
  • 13
  • 100
  • 152
Michael
  • 6,377
  • 14
  • 59
  • 91
  • See: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags –  Feb 25 '11 at 19:44

2 Answers2

0

Try removing the pattern outside the preg.

$pattern = "/$var1(.*)$var22/m";   //adding /s might help with the /m

this way you can echo $pattern; and check if it is valid.

lockdown
  • 1,456
  • 5
  • 16
  • 32
0

Your pattern contains lots of characters that have special meanings in regex, so it's confusing preg_replace about what to search for. Just use str_replace instead, because you really don't need regex for this. Haven't done PHP in a while, but try:

$pos1 = stripos($htmlcontent, $var1);
$pos2 = strripos($htmlcontent, $var2);

$content = substr_replace($htmlcontent, "", $pos1, $pos2 + strlen($var2));

And there is one point that cannot be emphasized enough.

Community
  • 1
  • 1
Justin Morgan - On strike
  • 30,035
  • 12
  • 80
  • 104