Reputation: 437
I have a MySQL database with collation latin1_swedish_ci.
The field look like this in the DB:
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
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