Roger Travis
Roger Travis

Reputation: 8548

PHP, text echos out of database without new line, all in one piece

I have a longtext in a database. It looks fine from php_mayadmin, but when I echo it out to a page, it loose all formatting, i.e. no new lines, all in one chunk. Any ideas? :)

Thanks!

Upvotes: 2

Views: 1944

Answers (3)

Alex Zylman
Alex Zylman

Reputation: 920

The string is stored with newlines representing the linebreaks. When you echo that, it just echos it into the source, so there are line breaks in the code. However, you want to have <br /> tags where the line breaks would be. PHP's nl2br function should work converts linebreaks into HTML <br> tags - that should do what you want.

Upvotes: 1

Iznogood
Iznogood

Reputation: 12853

Probably because the linebreaks are \n and html wants <br /> so use nl2br()

Upvotes: 7

Tom
Tom

Reputation: 541

It's because phpMyAdmin is using wordwrap().

Upvotes: 1

Related Questions