Page 1 of 1

str_replace issue

Posted: Sun Apr 19, 2009 5:55 pm
by cmartin19
Hello,
when content is cut and pasted into a textarea html box, and then sent to a mysql database for storage, there are certain characters within the cut and pasted content that the mysql database does not understand, namely ” , “ , and ’ the characters. Yet when these characters are typed in directly and not cut and pasted, mysql recognizes them and displays them properly. Currently, mysql replaces the above unrecognized characters with �. I tried to replace the characters with the correct versions using str_replace as in the following:

$txt_abstract = str_replace('“', '"', $txt_abstract);
$txt_abstract = str_replace('”', '"', $txt_abstract);
$txt_abstract = str_replace('’', ''', $txt_abstract);

the problem is I get the following syntax error:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING

Would appreciate any help on this hurdle. Thanks, Cm 8O

Re: str_replace issue

Posted: Sun Apr 19, 2009 6:15 pm
by requinix

Code: Select all

$txt_abstract = str_replace('“', '"', $txt_abstract);
$txt_abstract = str_replace('”', '"', $txt_abstract);
$txt_abstract = str_replace('’', ''', $txt_abstract);
 
Get yourself an editor with syntax highlighting.

You need to pick a good character encoding. UTF-8 is the most common one.
You make your tables' encoding that format then run your strings through utf8_encode before putting them into the query.