Jump to content

Smart Quotes = ‘ ??


neoform

Recommended Posts

For some reason, when i submit a textfield with this: [quote]“spies” ‘ticket’[/quote] as the value through a POST form, then insert it into a mysql table, this is what ends up in the table: [quote]‘spies’ “ticket”[/quote]

To sanitize my forms i use this:

[code]function safe_string($str)
{
if (get_magic_quotes_gpc())
$str = stripslashes($str);

//tried this to replace the smart quotes..  no good. :(
$search = array('‘','’','“','”');
    $replace = array("'","'",'"','"');
$str = ereg_replace($search, $replace, $str);

return mysql_real_escape_string(trim($str));
}[/code]

Anyone know why this might be happening? My table is using "latin1 -- cp1252 West European" as the charset, and i checked PHP, it's using UTF8..  it's breaking my brain since i've been messing with this for about 10 hours now and I still can't figure it out..
Link to comment
Share on other sites

Latin 1 - 1252 has:

[quote]
91 2018 LEFT SINGLE QUOTATION MARK
92 2019 RIGHT SINGLE QUOTATION MARK
93 201C LEFT DOUBLE QUOTATION MARK
94 201D RIGHT DOUBLE QUOTATION MARK
[/quote]

Try:

[code]
$str = preg_replace('/[\x91-\x92]/', "'", $str);
$str = preg_replace('/[\x93-\x94]/', '"', $str);
[/code]
Link to comment
Share on other sites

Are you specifying the charset in your meta? This works for me:

[code]
<meta charset="cp1252">
<pre>
<?php
print_r($_POST);
foreach ($_POST as $k => &$v) {
$v = preg_replace('/[\x93-\x94]/', '"', $v);
}
print_r($_POST);
?>
</pre>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<textarea name="test"><?php echo "\x93test\x94"; ?></textarea>
<input type="submit"/>
</form>
[/code]
Link to comment
Share on other sites

omg! that's it!!

THAT's what it was..  the page's content type. ack, i just copied/pasted it from another page.. ehhh

[code]<meta http-equiv="Content-Type" content="text/html; charset=utf-8">[/code]

every other site on my server uses

[code]<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">[/code]

Which explains why this problem has never cropped up on me.. :P
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.