shishisu Posted June 26, 2007 Share Posted June 26, 2007 Hi guys, I need some help here... Any input is greatly appreciated: I have a long string of HTML code, looks kind of like this: this is a test link to <!--source--><a href="www.apple.com">Apple</a><!--replace--><!--<a href="www.mozilla.org">Mozilla</a>--><!--end--> I would like to use a PHP script to find all the occurrence of <!--source--> and replace everything up to <!--replace--> with the text before <!--end--> The result string should look like: this is a test link to <a href="www.mozilla.org">Mozilla</a> Quote Link to comment Share on other sites More sharing options...
effigy Posted June 26, 2007 Share Posted June 26, 2007 <?php $string = <<<STR this is a test link to <!--source--><a href="www.apple.com">Apple</a> <!--replace--><!--<a href="www.mozilla.org">Mozilla</a>--><!--end--> STR; print $string = preg_replace('/<!--source-->.+?<!--replace--><!--(.+?)--><!--end-->/s', '\1', $string); ?> Quote Link to comment Share on other sites More sharing options...
shishisu Posted June 26, 2007 Author Share Posted June 26, 2007 Thanks Effigi! Regular expression guru... Quote Link to comment 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.