tryingtolearn Posted February 19, 2007 Share Posted February 19, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/39230-solved-help-needed-on-what-i-thin-is-preg_replace/ Share on other sites More sharing options...
tryingtolearn Posted February 19, 2007 Author Share Posted February 19, 2007 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?? Quote Link to comment https://forums.phpfreaks.com/topic/39230-solved-help-needed-on-what-i-thin-is-preg_replace/#findComment-189043 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.