PHP declare encoding
PHP 5.6 comes with a new default charset directive set to UTF-8
, in some case this may be a problem with pages served in metatag as latin1, you can override this directive by calling ini_set('default_charset', 'iso-8859-1')
in your scripts.
For doing that put on each php file you want to be coded to latin1 this piece of code at the beginning of your scripts:
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" under your root website and put this piece of code into config.php
:
example: config.php
<?php
##########################################################################
# Server Directive - Override default_charset utf-8 to latin1 in php.ini #
##########################################################################
@ini_set('default_charset', 'ISO-8859-1');
?>
If your php.ini is set to latin1 (ISO-8859-1
) and you want serve a utf-8 (unicode) page you can force encoding using the same way but putting instead of iso-8859-1, utf-8. Look at that:
example: config.php
<?php
##########################################################################
# Server Directive - Override default_charset latin1 to utf-8 in php.ini #
##########################################################################
@ini_set('default_charset', 'UTF-8');
?>
I hope you find my answer useful, I solved my problem in this way!