View Full Version : Removing font tags inside <!-- --> comments with PCRE

11-08-2006, 09:00 PM
Hi. Like I said in the title. I need to remove <font color="#xxxxxx">blah</font> text instead off getting rid of anything else like the blah.

Here's my HTML code:

&lt;<font color="#800080">script</font> type=<font color="#3A6EA5">&quot;text/javascript&quot;</font>&gt;<font color="#008000">&lt;!--
<br />
google_ad_client = <font color="#3A6EA5">&quot;pub-2364887827571271&quot;</font>;
google_ad_height = 90;
<br />
google_color_border = <font color="#3A6EA5">&quot;E1EBFF&quot;</font>;
<br />
google_color_text = <font color="#3A6EA5">&quot;677695&quot;</font>;
<br />
//--&gt;</font>&lt;/<font color="#800080">script</font>&gt;
<br />
&lt;<font color="#800080">script</font> type=<font color="#3A6EA5">&quot;text/javascript&quot;</font>
<br />

Here's a sample:

text text text <!-- this text is not going to be removed but the tag: <font color="#xxxxxxx">this will stay</font> tag will be removed...-->
This tag wont be removed because its outside the html comments tags <font color="#xxxxxx">sdg</font>

My code so far:

$text = preg_replace("/(&lt;!--)(.*?)(<font color=\"#[\d\w]{6}\">)(.*?)(<\\/font>)(.*?)(--&gt;)/si","\\1\\2\\4\\6\\7",$text);

EDIT: I am making a HTML code highlightor and it put font color tags inside comment tags and it should not do that because all text inside comments tags will be the same color...

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum