JDelage
JDelage

Reputation: 13692

Why is my internal encoding ISO-8859-1 when I have specified utf-8 in my php.ini file?

In my php.ini file, I have included mbstring.internal_encoding = "UTF-8". (I have tried with or without double quotes, capitalized or not.)

Yet when I run echo "current internal encoding: ".mb_internal_encoding();, I still get ISO-8859-1.

Why is this, and is there anything I can do in the php.ini file to set internal encoding once and for all?

I'm using WAMPserver on a WinXP laptop.

Upvotes: 3

Views: 1835

Answers (2)

Alessandro
Alessandro

Reputation: 908

To be sure to override default_charset of yours php.ini use this way, use ini_set('default_charset', 'Your Charset');

put on each php file this piece of code at the beginning...

example: index.php

<?php
  $server_root = realpath($_SERVER["DOCUMENT_ROOT"]);
  $config_serv = "$server_root/php/config.php";
  include("$config_serv");
?>

then create a folder "php" inside your root server and put this file... this piece of code serves latin1 overriding utf-8...

config.php

<?php
  ##########################################################################
  # Server Directive - Override default_charset utf-8 to latin1 in php.ini #
  ##########################################################################
  @ini_set('default_charset', 'ISO-8859-1');
?>

or this other one... this piece of code serves utf-8 overriding latin1... Use the first or the second according to your needs...

config.php

<?php
  ##########################################################################
  # Server Directive - Override default_charset latin1 to utf-8 in php.ini #
  ##########################################################################
  @ini_set('default_charset', 'UTF-8');
?>

Upvotes: 0

spencercw
spencercw

Reputation: 3358

As mentioned in the comments this is because there are usually at least two php.ini files: one for the command line version and one for the Apache plugin. You need to make sure you edit the right one.

This is not an uncommon problem and I've certainly been bitten by it before.

Upvotes: 3

Related Questions