Reputation: 113
I am getting <br />
for every newline in textarea after I load the values from the database
I try to use these but it does not change anything
nl2br($house_address);
Any tips?
Upvotes: 2
Views: 8331
Reputation: 730
nl2br($house_address)
replaces new lines with the <br />
, you don't need to use it.
Do you store <br/>
's in a database? Is so, use strip_tags()
to strip them.
It's much better to store the plain text and process it prior the output.
Upvotes: 1
Reputation: 6013
nl2br
does the opposite of what you want to do.
you could do
$house_address = str_replace('<br />', "\n", $house_address);
or this
$house_address = preg_replace('#<br\s*/?>#', "\n", $house_address);
Also, You really should do this before you insert the data into the database (or preferably strip_tags($house_address)
).
Upvotes: 4
Reputation: 22741
Try this,
$address = str_replace('<br />', '\n\t', $address);
$address = str_replace('<br>', '\n\t', $address);
OR
$address = str_ireplace('<br />', '\n\t', $address);
Upvotes: 2