Php ZipArchive() - special characters not displayed correctly when listing filenames

I have tried EVERYTHING and asked the question on 3 different php forums but nobody could come up with a solution. I’m desperate !

I have a FTP on a dedicated server where my users uploads mp3 in zip files. I use a php page to display the list of the filenames inside the archive.

Problem is that when some of the mp3 filenames have accents (like é à ê à â ô ç ï) then it is not displayed correctly even if the page is set to use UTF8.

for exemple, “é” will become " ‚ "
“ô” will become " “ "
“ê” will become " ˆ "

<?php
header('Content-Type: text/html; charset=utf-8');

setlocale(LC_ALL, 'fr_FR');

echo "
<html>
<head>
<meta http-equiv=\\"Content-type\\" content=\\"text/html; charset=utf-8\\" />
</head>
<body>";

$downloadlink = "dl/pp/86 Crew - 2000 - Bad Bad Reggae.zip";
$za = new ZipArchive();
$za->open($downloadlink);
for( $i = 0; $i < $za->numFiles; $i++ ){
$stat = $za->statIndex( $i );
$tounes = array( basename( $stat['name'] ) . PHP_EOL );
foreach($tounes as $toune) {
echo "$toune <br>";
}
}

echo "</body></html>";
        ?>

basename is locale dependant. check your default locale setting first.


echo setlocale(LC_ALL, 0);

echo setlocale(LC_ALL, 0);
result is:

C

Not sure what it means and how it is revelent for my problem…

Try setting your locale to utf8.

setlocale(LC_ALL, ‘en_US.UTF-8’);

Just tried it, and it doesnt change anything :frowning:

i have also tried with fr_CA.UTF-8 which should be the correct encoding for my files and my server