Jump to content

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


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??

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.