Jump to content

Remove last <br /> of each line


The Little Guy

Recommended Posts

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

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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.