Andy
Andy

Reputation: 3021

maintaining carriage returns from a mysql entry

How can i maintain the description of a product as i can see it in the mysql database which includes the carriage returns e.t.c but no HTML.

Is there a function in PHP which can interpret the bits required so when it renders it has
or

?

Upvotes: 0

Views: 2854

Answers (3)

Ben Lee
Ben Lee

Reputation: 53319

If I understand you correctly, you probably want to use this function:

$text_to_display = nl2br($text_from_database);

This will add a br tag before all newlines, so it will show up as line breaks in the html output.

Upvotes: 1

Surreal Dreams
Surreal Dreams

Reputation: 26380

nl2br(), described here: http://php.net/manual/en/function.nl2br.php

This function converts the newline character into <br /> tags. This preserves newlines visually in HTML.

Upvotes: 1

ceejayoz
ceejayoz

Reputation: 180024

HTMl doesn't honour carriage returns. PHP has the nl2br function to insert <br /> tags where carriage returns are present.

Upvotes: 3

Related Questions