Posted by Pugi! on 03/20/07 20:36
matthud@gmail.com wrote:
> The following string:
> "US generals ‘will quit’ if Bush orders Iran attack"
>
> is being stored in my table as:
>
> "US generals ‘will quit’ if Bush orders Iran attack"
>
> The only PHP function I'm applying to the string is
> mysql_real_escape_string, and that doesn't appear to be the root of
> the problem. I'm using utf8_general_ci as my collation.
>
> Forgive my ignorance.
>
When using UTF-8 you should use it everywhere: database collation, table
and field collation. In php.ini (or is it apache.conf httpd.cong) set
default characterset to utf-8. With firefox web developers toolbar you
check header information.
After connecting to database and before executing any queries add
following line to code:
mysql_query("SET NAMES 'utf8'");
You can also set default characterset (utf-8) in .htaccess file (instead
of php.ini or was it apache.conf). Don't have access to webserver for
the moment.
At the same time I also stopped using mysql_real_escape_string and
started using strip_tags.
Worked. Just have one problem left. When I redisplay information in form
(to modify) I get those funny characters back. Probably something I
overlooked. Information is stored in database OK (phpmyadmin and command
line readable), is displayed correctly on webpage.
Hope this helps.
I got info from
http://www.fedora-linux.nl/forum/viewtopic.php?p=12358&sid=b1d3b9e01e16065aa66ea0457a49a053
(information is in dutch)
Pugi!
[Back to original message]
|