str_replace issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cmartin19
Forum Newbie
Posts: 5
Joined: Thu May 15, 2008 8:07 pm

str_replace issue

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: str_replace issue

Post 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.
Post Reply