0

Here I found a wonderful solution for recursively change the encoding of the files of one folder Randomseed solution

$path = realpath('C:\\your\\path');

$iterator = new RecursiveIteratorIterator(
    new RecursiveDirectoryIterator($path), 
    RecursiveIteratorIterator::SELF_FIRST
);

foreach($iterator as $fileName => $file){
    if($file->isFile())
        file_put_contents(
            $fileName,
            iconv('ISO-8859-7', 'UTF-8', file_get_contents($fileName))
        );
}

But there is a problem. Every file is changed, even images, and they are not shown later. How to edit this for changing only .php files for example?

Thank you very much!

Azeem
  • 11,148
  • 4
  • 27
  • 40
Betty
  • 1

1 Answers1

0

If you only want to loop over .php files, Simply look at the extension of the file.

    foreach($iterator as $fileName => $file){
    if($file->isFile() && $file->getExtension() == "php")
        file_put_contents(
            $fileName,
            iconv('ISO-8859-7', 'UTF-8', file_get_contents($fileName))
        );
   }
Gerrit Luimstra
  • 522
  • 6
  • 23