Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replace br tag from a string in php

Tags:

regex

php

I have the following string. I want to replace the line break with /n

Good FRIENDS are hard to find,<br
            /> harder to leave,<br
            /> and impossible to forget.
like image 929
Renjith R Avatar asked May 01 '11 14:05

Renjith R


People also ask

How do I replace my br tag?

replace() method to replace all the line breaks in the plain text with the <br> tag. Here the RegEx refers to the regular expression that we write inside the string. replace() method.

How do you remove a BR tag from a string?

The line break can be removed from string by using str_replace() function.


1 Answers

preg_replace("/<br\W*?\/>/", "\n", $your_string);
like image 192
hsz Avatar answered Oct 05 '22 08:10

hsz