I know for sure that this was already been asked before but I just googled around and couldn’t find anything (maybe wrong word choice?).
Just don’t be too mad at me, I’m getting mad too…
I’d like
$string = '
This is a line
This is another line
';
to be shown to the HTML page as
This is a line
This is another line
when I do echo $string;.
How can I capture the return key or the new line and replace it with <br>?
Try the
nl2br()function:Would return:
To trim off the leading and trailing new lines, use
trim():Would return: