Jump to content

[SOLVED] Help needed on what I thin is preg_replace???


tryingtolearn

Recommended Posts

Hi again all,

 

I am totally confused over this preg_replace

Basically I am not sure what function I should be using to accomplish something.

 

What I need to do is convert everything between multiple html comment tags so they do not get stripped when using strip tags.

 

So if I start with this

Bunch of html code

<!-- STARTMARK --><img src="graphics/pic1.gif" width="40" height="40" alt="mypic1" border="0"><!-- ENDMARK -->

<img src="graphics/pic2.gif" width="40" height="40" alt="mypic2" border="0">

<!-- STARTMARK --><img src="graphics/pic3.gif" width="40" height="40" alt="mypic3" border="0"><!-- ENDMARK -->

Bunch of html code

 

It will change to something like this

 

Bunch of html code

<!-- STARTMARK --><img src="graphics/pic1.gif" width="40" height="40" alt="mypic1" border="0"><!-- ENDMARK -->

<img src="graphics/pic2.gif" width="40" height="40" alt="mypic2" border="0">

<!-- STARTMARK --><img src="graphics/pic3.gif" width="40" height="40" alt="mypic3" border="0"><!-- ENDMARK -->


Bunch of html code

 

So I can run it through strip tags and end up with this

 

Bunch of text

<!-- STARTMARK --><img src="graphics/pic1.gif" width="40" height="40" alt="mypic1" border="0"><!-- ENDMARK -->


<!-- STARTMARK --><img src="graphics/pic3.gif" width="40" height="40" alt="mypic3" border="0"><!-- ENDMARK -->



Bunch of text

 

There can be any # of the STARTMARK and ENDMARK tags from 0-100 it will just depend on the page.

 

I have everything but converting only those marked sections

Can this be done?

 

 

 

Im this far but am lost when it comes to replacing everything in the middle of the tags.

 

$search = array ("'<!-- STARTMARK --[^>]*?>.*?<!-- ENDMARK -->'si");
$replace = array ("<!-- STARTMARK -->.*<!-- ENDMARK -->"); 
$new = preg_replace ($search, $replace, $source);

 

Is this at least in the ballpark??

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.