JohnSmith
JohnSmith

Reputation: 437

Outputing content from db generate double line breaks

I have a MySQL database with collation latin1_swedish_ci.

The field look like this in the DB:

enter image description here

When outputing I do like this:

echo str_replace("<br />", "\n", trim($post->getContent()));

$post->getContent() is just fetching the field from the DB, no manupalating from DB to echo.

The thing is when I update the field I get double line breaks (just updating without adding line breaks).

How come I get this and how do I solve it?

Upvotes: 0

Views: 60

Answers (1)

Mihai Iorga
Mihai Iorga

Reputation: 39724

Remove <br /> completely, you already have an \n in database, you are making 2 new lines when you replace <br /> with \n:

echo str_replace("<br />", "", trim($post->getContent()));

Upvotes: 4

Related Questions