PDA

View Full Version : PHP display of multiline mysql value



Mike
19-03-2010, 06:36 PM
OK, so how do I explain this one :)

I have a multiline string in a mysql varchar that I want to display in a webpage (PHP), however whenever I display it it only displays as a single line...

What do I need to do to display the string 'correctly' (with new lines at the right place)?

Cheers,
Mike.

MushHead
19-03-2010, 08:19 PM
Not sure what the line delimiter would be in a multiline field, but assuming it's a linefeed, what do you get by displaying the result of


implode("<br>", explode("\n", $mysql_var))

Mike
19-03-2010, 08:25 PM
Haha thanks MushHead, I just came back to say that I've figured it, and you've posted pretty much the same thing :)

I didn't use the implode in mine, just the explode("\n", $mysql_var)

Cheers,
Mike.

Erayd
19-03-2010, 10:10 PM
Not sure what the line delimiter would be in a multiline field, but assuming it's a linefeed, what do you get by displaying the result of


implode("<br>", explode("\n", $mysql_var))

That's a very inefficient way or doing it - use
nl2br($mysql_var);or
str_replace("\n", "<br />", $mysql_var);Nl2br() is the better of those two options.