Re: character sets
From: NC (nc_at_iname.com)
Date: 02/01/05
- Next message: Sean: "Re: Pathfinding in community"
- Previous message: Janwillem Borleffs: "Re: MySQL help"
- In reply to: WindAndWaves: "character sets"
- Next in thread: Andy Hassall: "Re: character sets"
- Reply: Andy Hassall: "Re: character sets"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 1 Feb 2005 13:40:47 -0800
WindAndWaves wrote:
>
> The encoding that I use on my webpage is:
> <META HTTP-EQUIV="content-type" CONTENT="text/html; charset=UTF-8">
>
> When people enter new data I use
> $newvalue = htmlentities($_POST["newvalue"], ENT_QUOTES)
>
> I then SQL this into my table and next I display the value
> e.g. <DIV CLASS="content">'.$newvalue.'</DIV>
>
> All of this works fine, BUT, funny characters that may have been
> entered through the form (e.g. Word-Style quotation marks,
> e-accent-grave, etc..) are taking on a whole new life.
> I put in an e with an accent and it changed into a chinese
> character.
You have two options to fix this:
1. Convert your strings from UTF-8 into, say, ISO-8859-1,
before storing them in the database:
$string = iconv('UTF-8', 'ISO-8859-1', $string);
You will need your PHP installation to be compiled
with iconv extension to do that.
2. Set your MySQL server's character set to UTF-8.
First, check if you currently have UTF-8 support.
Run this query:
SHOW VARIABLES;
find the `character_sets` variable in the output and
verify that `utf8` is listed among the character sets
currently supported. If there's no support for UTF-8,
install or configure it (see MySQL documentation for
details).
If and when you have UTF-8 support, you can set
UTF-8 as the default character set for your database:
ALTER DATABASE db_name
DEFAULT CHARACTER SET utf8;
Alternatively, you can change character set setting
on a per-connection basis by sending this query:
SET NAMES 'utf8';
first thing after establishing a connection to the
database.
Cheers,
NC
- Next message: Sean: "Re: Pathfinding in community"
- Previous message: Janwillem Borleffs: "Re: MySQL help"
- In reply to: WindAndWaves: "character sets"
- Next in thread: Andy Hassall: "Re: character sets"
- Reply: Andy Hassall: "Re: character sets"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|