The nl2br function adds <br/> after each line break character ( \r\n, \n\r, \n and \r ).
However, it does not remove the break line. As a result, when you use str_replace to add a line break, it appears as double.
There are two options: first, change str_replace to just delete <br/> without adding a new line character or, secondly, not use nl2br .
I would choose the second one and use nl2br when I need to display data inside html.
source share