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> Link to comment https://forums.phpfreaks.com/topic/57185-string-replacement-need-help/ 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); ?> Link to comment https://forums.phpfreaks.com/topic/57185-string-replacement-need-help/#findComment-282565 Share on other sites More sharing options...
shishisu Posted June 26, 2007 Author Share Posted June 26, 2007 Thanks Effigi! Regular expression guru... Link to comment https://forums.phpfreaks.com/topic/57185-string-replacement-need-help/#findComment-283534 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.