I have a medium sized text area that takes user input. Somewhere between one and 5 paragraphs.
What functions should I run on the incoming text to clean it for database storage?
mysql_real_escape_string(), of course, but that doesn't detect and convert non-standard characters, does it?
Specifically:
*When the user pastes content from MS Word, you get 'quotes' that aren't actually quotes and all sorts of other strange characters.
*If the user inserts line breaks, should I convert them to HTML? Should I use HTML_special_chars()? Will that be enough?
*I'm thinking that I do want to allow HTML markup, for formating purposes.
On one of the Zen Cart powered sites I maintain, there's all sorts of strange things in the "product descriptions" field that cause the Google Base feed to choke. Most of this is from 'Word pasting'. I'd like to avoid any non-standard character weirdness this time around.... Any ideas?
And on the database end, do you use BLOB or Text?
Cleaning Up and Storing Text Area Contents
Moderator: General Moderators
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: Cleaning Up and Storing Text Area Contents
In the database i just use TEXT data type.
To make sure the text is stored and restored correctly you could use url_encode()
To make sure the text is stored and restored correctly you could use url_encode()
Re: Cleaning Up and Storing Text Area Contents
So I should do something like:
Code: Select all
$TextPastedFromWord = $_GET['MyTextArea'];
$CleanText = rawurlencode(htmlentities($TextPastedFromWord));
$TextToInsert = mysql_real_escape_string($CleanText);
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: Cleaning Up and Storing Text Area Contents
Looks good to me. Give it a whirl.