I want to filter / reject the following chars from form input: ' (which seems to be the most difficult) - _ (the last 2 I have some success with) I've tried \' but that doesn't seem to do any good. Any help? Thanks.
Thanks for the quick response. When I try to use your suggestion, it filters everything (so I get no results). Any ideas? $SearchString = str_replace($SearchString, "'", ' '); $SearchString = trim($SearchString); $SearchString = preg_replace('/\s\s+/', ' ', $SearchString);
Should be: $SearchString = str_replace("'", '', $SearchString); $SearchString = trim($SearchString); $SearchString = preg_replace('/\s\s+/', ' ', $SearchString); Code (markup): There is mistake in my first post.
Can I do multiple replacements in the same statement, or do I have to issue the statement over and over again to clean everything out? Say I want to get rid of _ - ' etc.?
You can create function: function cleanOut($SearchString) { $SearchString = str_replace("'", '', $SearchString); $SearchString = trim($SearchString); $SearchString = preg_replace('/\s\s+/', ' ', $SearchString); return $SearchString; } $text = cleanOut( $text ); Code (markup):
Ok, one last one - " How do I filter for that? $SearchString = str_replace(""", '', $SearchString); that's not going to work.