PHP nl2br on one line

I usually store data from a textarea directly to the database as is, then once I retrieve it back into HTML I use that lovely PHP function nl2br() to convert it to HTML

This works well for most cases until you are passing this data back into javascript where everything has to be on one line!

nl2br() outputs as follows:

Line one
Line two

And I want it to be as follows:

Line one
Line two

So how do I do this?

echo trim(strtr($myOriginalString, array(\r\n => 
, \r => 
, \n => 

Leave a Reply

Your email address will not be published.