The Little Guy Posted July 10, 2010 Share Posted July 10, 2010 I have the following line, I want it to remove the last <br /> of ever line that is between [noformat][/noformat] if there are 2+ <br /> tags only remove the last one $text = preg_replace("~\[noformat\](.*?)\[\/noformat\]sei~", "preg_replace('~\<br \/\>$~', '', $1)", $text); The following does nothing.... How can I do what I described? Link to comment https://forums.phpfreaks.com/topic/207319-remove-last-of-each-line/ Share on other sites More sharing options...
wildteen88 Posted July 10, 2010 Share Posted July 10, 2010 You have your pattern modifiers in the wrong place. Pattern modifiers should be placed after the closing delimiter ~\[noformat\](.*?)\[\/noformat\]~sei Also you'll need to wrap $1 within quotes too "preg_replace('~\<br \/\>$~', '', '$1')" Fixed code $text = preg_replace("~\[noformat\](.*?)\[\/noformat\]~sei", "preg_replace('~\<br \/\>$~', '', '$1')", $text); Link to comment https://forums.phpfreaks.com/topic/207319-remove-last-of-each-line/#findComment-1084121 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.