JasonLewis Posted August 18, 2008 Share Posted August 18, 2008 I'm not sure why this isn't working, but it isn't. I just can't seem to get it. This is my expression: $tmp_tpl = preg_replace("#<!--COMMENTBOX-->(.*?)<!--ENDCOMMENTBOX-->#", "", $tmp_tpl); I just want to replace ANYTHING between the two tags with nothing. Cheers everyone. Quote Link to comment Share on other sites More sharing options...
nrg_alpha Posted August 18, 2008 Share Posted August 18, 2008 Well, one way is to make use of assertions. By using look behind and look ahead assertions (they are not included in any matches), you can grab what is not part of them: $tmp_tpl = preg_replace('#(?<=<!--COMMENTBOX-->).+(?=<!--ENDCOMMENTBOX-->)#', '', $tmp_tpl); Of course, to test this out, when you say echo $tmp_tpl, you won't see anything, as these are comment tags (and thus do not display). So you would have to right-click and view source to see the '<!--COMMENTBOX--><!--ENDCOMMENTBOX-->' effect. Cheers, NRG Quote Link to comment Share on other sites More sharing options...
effigy Posted August 18, 2008 Share Posted August 18, 2008 Use the /s modifier: #<!--COMMENTBOX-->(.*?)<!--ENDCOMMENTBOX-->#s. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted August 19, 2008 Author Share Posted August 19, 2008 Thanks for the replies guys. Adding the modifier worked though, cheers. 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.