Why is my internal encoding ISO-8859-1 when I have

2019-07-03 11:51发布

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.

2条回答
【Aperson】
2楼-- · 2019-07-03 12:46

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.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-07-03 12:49

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');
?>
查看更多
登录 后发表回答