views:

285

answers:

2

I am trying to convert my existing PHP webpage to use UTF-8 encoding.

To do so, I have done the following things:

  1. specified UTF-8 as the charset in the meta content tag at the start of my webpage.
  2. change the default_charset to UTF-8 in the php.ini.
  3. specified UTF-8 as the iconv encoding in the php.ini file.
  4. specified UTF-8 in my .htaccess file using: AddDefaultCharset UTF-8.

Yet after all that, when i echo mb_internal_encoding(), it shows as ISO-8859-1. What am I missing here? I know I could use auto_prepend to attach a script that changes the default encoding to UTF-8, but I'm just trying to understand what I'm missing.

Thanks

A: 

The documentation states that you can SET that variable using

/* Set internal character encoding to UTF-8 */
mb_internal_encoding("UTF-8");

which should get rid of your problem :)

Martin Hohenberg
yes I understand that I could set the encoding using that function, but it seems redundant to set the internal encoding on every page, when i'm sure there's a global place to specify the encoding.
justinl
+3  A: 

mb_internal_encoding() doesn't effect the output of your scripts per se, it effects the default encoding when using the multibyte string functions and the conversion of POST and GET inputs.

Simply set with

mbstring.internal_encoding='UTF-8'

in your php.ini file, or programmatically with:

mb_internal_encoding('UTF-8');

Speaking of the mb_ functions, you'll need to rewrite your scripts to use these, e.g. mb_strlen() instead of strlen.(), etc.

Also check what HTTP content-type headers are being outputted, though from what you've done it should be ok.

If you using a database, you'll also have to convert that too, and specify that you're using UTF-8 when connecting to it.

Pete
Thanks. that mbstring.internal_encoding (in the php.ini) worked perfectly and was what i was looking for, compared to setting it on every page using php.
justinl