I am inserting data from a textarea into a text field in a database. I need to allow for two things.
1. I need to allow special characters which is easy using addslashes.
2. I need to preserve html formatting. I am using overlib to display the data. If I enter:
The Dog Is
Brown
Then I would like it to display in overlib the same way. Is there a html encode / decode function that I could use?
Thanks!
HTML Encode / Decode
Moderator: General Moderators
- aerodromoi
- Forum Contributor
- Posts: 230
- Joined: Sun May 07, 2006 5:21 am
Re: HTML Encode / Decode
From what I gather you don't need any "html encode / decode function" - you just have to convert linebreaks "\r\n" to <br />.peterro wrote:If I enter:
The Dog Is
Brown
Then I would like it to display in overlib the same way. Is there a html encode / decode function that I could use?
Thanks!
eg. with preg_replace
aerodromoi
Code: Select all
printf('<textarea>%s</textarea>', htmlspecialchars($string, ENT_NOQUOTES, 'UTF-8'));PS: don't use nl2br, you will introduce rogue <br> tags into your data.