golfromeo Posted October 17, 2009 Share Posted October 17, 2009 I am coding a PHP pm system. In it, when a user hits reply, the server adds a and a [/quote ] to each end of the message so when the user replies, the old message will show up as a quote... However, I only want there to be one trailing message. Therefore, is there a way in PHP Regex to remove everything between the [/quote ] tags, and them remove the quote tags themselves? For example, if the input was: Here is my reply. My first message[/quote ] The output should be: Here is my reply. Quote Link to comment https://forums.phpfreaks.com/topic/177991-solved-remove-quoteand-everything-in-it-quote/ Share on other sites More sharing options...
Garethp Posted October 17, 2009 Share Posted October 17, 2009 $Content = preg_replace('~\[quote\].+?\[/quote\]~', '', $Content); Quote Link to comment https://forums.phpfreaks.com/topic/177991-solved-remove-quoteand-everything-in-it-quote/#findComment-938495 Share on other sites More sharing options...
thebadbad Posted October 17, 2009 Share Posted October 17, 2009 Add is after the last ~ to make the search case insensitive and to make the dot match line breaks. If it also should remove empty quote tags like , use an asterisk instead of the plus. ~\[quote\].*?\[/quote\]~is Quote Link to comment https://forums.phpfreaks.com/topic/177991-solved-remove-quoteand-everything-in-it-quote/#findComment-938556 Share on other sites More sharing options...
golfromeo Posted October 17, 2009 Author Share Posted October 17, 2009 Thanks a lot, worked great. I've gotta learn Regex sometime.... Quote Link to comment https://forums.phpfreaks.com/topic/177991-solved-remove-quoteand-everything-in-it-quote/#findComment-938635 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.