mistysnake
mistysnake

Reputation: 113

How to remove <br /> from textarea after load from database?

enter image description here

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

Answers (4)

kost
kost

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

Xyz
Xyz

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

Krish R
Krish R

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

sjagr
sjagr

Reputation: 16512

Use strip_tags:

echo strip_tags($house_address);

Upvotes: 6

Related Questions