0

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?

Rim
  • 185
  • 3
  • 3
  • 11

2 Answers2

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