Keeping Whitespace But Remove Characters PHP

Soldato
Joined
30 Nov 2005
Posts
3,084
Location
London
I'm inserting some values into a MySQL database but want to remove any suspicious characters whilst preserving whitespace.

Would just mysql_real_escape_string be sufficient in terms of security?

Cheers.
 
Yes, but it won't actually remove any characters, just escape them so they'll be safe to use in a MySQL query.

If you want to remove particular characters, you need to write an expression to filter them out specifically. How you write that depends on what you consider 'suspicious'. Do you just want numbers, just letters, just uppercase characters, no punctuation etc.
 
Well I want to keep numbers and letters (Upper and Lower case are fine), plus punctuation such as Full stop, question mark and exclamation mark.

Everything else such as Quotes etc would rather remove.

I've tried looking on Google and most of the 'replace strings' remove whitespace aswell.
 
Back
Top Bottom