I have local environnement development (WAMP) and production environnent on my hoster.
For testing purpose I export my database from hoster and import to my local WAMP environnement.
I have a fonction who take text from my database and generate json file for display.
To display accents I have to use utf8_decode on WAMP environnement but not on my hoster environnement. I checked everthing about encoding and configuration, even if I re-import the same SQL file from my computer on both sides (dev. and prod.) ths problem still exist.
PARAM | DEV | PROD |
---|---|---|
PHPMYADMIN VERSION | 5.2.0 | 5.2.1 |
EXPORT SQL FILE ENCODING | NA | uft-8 |
EXPORT SQL PARAMETER | (Import from PROD) | data & structure with drop |
IMPORT SQL FILE ENCODING | uft-8 | NA |
DATABASE INTERCLASSEMENT | latin1_swedish_ci | latin1_swedish_ci |
STRUCTURE FIELD COLLATION | latin1_swedish_ci | latin1_swedish_ci |
MYSQL VERSION | 8.0.31 | ??? |
PHPVERSION | 8.0.26 | 8.0.28 |
PHP COINFIG default_charset | UTF-8 / UTF-8 | UTF-8 / UTF-8 |
WEBSERVER | Apache/2.4.54 | Apache ??? |
So if I don't use utf8_decode in my function:
"content": "'.(str_replace($badchar, '',str_replace(array("\r\n","\r","\n"),'<br/>', $data['avis']))).'"
dev: "Région riche en découvertes." prod: "Région riche en découvertes."
if I use utf8_decode in my function:
"content": "'.utf8_decode(str_replace($badchar, '',str_replace(array("\r\n","\r","\n"),'
'
dev: "Région riche en découvertes." prod: "R�gion riche en d�couvertes."
I don't undersand where the problem come from, apache, mysql, php ?
The function mb_detect_encoding return me UTF-8 both sides.
Full function:
function refresh_json_avis($BDD)
{
$badchar=array(
// control characters
chr(0), chr(1), chr(2), chr(3), chr(4), chr(5), chr(6), chr(7), chr(8), chr(9), chr(10),
chr(11), chr(12), chr(13), chr(14), chr(15), chr(16), chr(17), chr(18), chr(19), chr(20),
chr(21), chr(22), chr(23), chr(24), chr(25), chr(26), chr(27), chr(28), chr(29), chr(30),
chr(31),
// non-printing characters
chr(127)
);
$SiteDataClass = new SiteDataClass($_SERVER['DOCUMENT_ROOT']."/json/config.json");
$req =$BDD->prepare('select avis, nom, date, appartement FROM reservations WHERE etat>=6 AND avis!="" ORDER BY date DESC, id DESC');
$req->execute();
$file='[';
while($data = $req->fetch())
{
$array_date=explode('-',$data['date']);
$file.='{"title": "'.$SiteDataClass->get_flat_name($data['appartement']).', '.$array_date[2].'/'.$array_date[1].'/'.$array_date[0].'","content": "'.utf8_decode(str_replace($badchar, '',str_replace(array("\r\n","\r","\n"),'<br/>', $data['avis']))).'","sign": "'.strtoupper(substr($data['avis'], 0, 1)).'."},';
}
$req->closecursor();
$file = rtrim($file);
$file = rtrim($file, ",");
$file.= "]";
file_put_contents($_SERVER['DOCUMENT_ROOT'].'/json/avis.json', $file);
return('[{"type":"message","content":"'.mb_detect_encoding($file).'","param":"success"}]'); //debug
return('[{"type":"message","content":"Mis à jour, cela peut mettre plusieurs minutes à apparaitre","param":"success"}]');
}