I have 1200 files encoded ANSI. I need to convert them into UTF-8. It is not reasonable to convert each file using the simple solution file/save as! Is there a commande in php which convert files from ANSI to UTF-8?
Asked
Active
Viewed 30 times
0
-
I use Windows and not Unix – Rim Sep 30 '15 at 22:50
-
ANSI = ASCII to you? – Federkun Sep 30 '15 at 22:52
-
it corresponds to ISO encoding I think – Rim Sep 30 '15 at 22:55
-
Is there a particular reason for using php? There are tons of similar questions on SO (and probably elsewhere) with solutions in many languages… There are also similar questions on [su], like [this one](http://superuser.com/q/113394) – Didier L Sep 30 '15 at 22:59
-
ISO? Okay. There are only a few dozen of those encoding. – Federkun Sep 30 '15 at 23:00
-
I am not very good in java but I will try the code mentioned – Rim Sep 30 '15 at 23:06
2 Answers
0
You can do this with the iconv library, which has a PHP binding (https://secure.php.net/manual/en/function.iconv.php). Consider using the command-line program to convert your source files instead, and keeping everything in utf8 instead of juggling encodings.

Davislor
- 14,674
- 2
- 34
- 49
0
I have found the solution using PHP. This is the code used:
<?php
set_time_limit ( 30000 );
$k=0;
while ($k<1232)
{
$fres="contenu_url".$k.".txt";
$inF = fopen($fres,"r");
$fres1="contenu_utf".$k.".txt";
$OutF = fopen($fres1,"w+");
$k=$k+1;
if($inF == false)
echo "<p>Impossible d'ouvrir le fichier</p>.\n";
$contenu_ancien="";
while (!feof($inF))
$contenu_ancien .= fgets($inF, 4096);
$contenu_utf8 = utf8_encode ($contenu_ancien);
fputs($OutF,$contenu_utf8);
fclose($OutF); fclose($inF);
}
?>

Rim
- 185
- 3
- 3
- 11