I want to replace newline \n. If there is one occurrence it gets replaced with <br>. If there are two or more in a row it gets replaced with <br><br>. I can do either or but I am not sure how to do both for the same variable.
I want to replace newline \n . If there is one occurrence it gets
Share
If you want to replace two or more with the same number of line breaks, str_replace should work.
If however, you want to replace three newline characters with only two line breaks then you’ll have to perform two replaces, at least one using a regular expression: