View Full Version : How do you strip quotes out of POST data?
I have an events calendar where people submit their own events. I have fields for meta description and meta keywords. People are entering double quotes into the fields which is messing things up.
How do you strip quotes out of the data before loading to the database? I already do this: $meta_keyword = mysql_real_escape_string($_POST['meta_keyword']); , but it doesn't help.
Thanks!
Is this a database problem, or are quotes simply not allowed for the type of information you're collecting? (Since you say "meta description," I'll assume this is for an HTML meta tag, where quotes would mess up the HTML output.)
Use str_replace (http://php.net/str_replace):
<?php
$quotes = 'I just wanted to say "Hello!"';
# three arguments:
# 1) the string to search for, in this case, " (double-quotes)
# 2) the string to replace with, in this case, nothing (an empty string)
# 3) the subject string
$noQuotes = str_replace( '"','',$quotes );
print $noQuotes;
/* prints
I just wanted to say Hello!
*/
If this is indeed for a meta tag, you'd probably want to strip out single-quotes as well:
str_replace( array( "'","'" ),'',$quotes );
# note, that's "'" (a single quote, in a double-quoted string) and '"' (a double-quote, in a single-quoted string).
Dear Adrian: Brilliant! That solved the one problem, which made it obvious that that was not the source of the problem. So then I was able to figure out that problem. So you actually solved 2 problems at once. Mahalo! aa :)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.