'. htmlspecialchars ($withVarTypes ? $var : print_r ($var, true)). ''; } function getFilesFrom($folder, $extension = '.php'){ $folderReader = opendir($folder); if($folderReader){ $listArray = array(); while(false !== ($folderEntry = readdir($folderReader))){ if (($folderEntry != '.' and $folderEntry != '..')){ if (is_dir($folder.'/'.$folderEntry)) { $tempListArray = getFilesFrom($folder.'/'.$folderEntry, $extension); $listArray = array_merge($listArray, $tempListArray); } elseif (substr($folderEntry, strripos($folderEntry, '.')) === $extension) { $listArray[$folder.'/'.$folderEntry] = array('file' => $folderEntry, 'path' => $folder.'/'.$folderEntry); } } } return $listArray; }else{ return array(); } } function rmkdir($path, $mode = 0777) { $folders = explode('/', $path); $path = ''; foreach($folders as $folder) { $path .= ($folder . '/'); if (!is_dir($path) && stripos($path, '.') === false) { mkdir($path, $mode); } } } // Settings header('Content-Type: text/html; charset=utf-8' ); error_reporting(E_ALL | E_STRICT); $translateToEncoding = 'windows-1250'; $previousEncodings = 'UTF-8'; $fileExtension = '.php'; $newFilesMainFolder = 'converted'; // Grab files $foldersToEncode = array('file_encoding_converter_folder'); foreach($foldersToEncode as $folder) { $files = getFilesFrom($folder, $fileExtension); foreach($files as $file) { $tempString = file_get_contents($file['path']); // Check in which encoding is file, convert $oldEncoding = mb_detect_encoding($tempString, $previousEncodings); if ($oldEncoding !== $translateToEncoding) { $tempString = iconv($oldEncoding, $translateToEncoding, $tempString); // re-encode $newFilePath = str_replace($folder, $newFilesMainFolder, $file['path']); // store file to a new location (we don't want to override previous files) // Create new file with right encoding rmkdir($newFilePath, 0777); file_put_contents($newFilePath, $tempString); dump('File: '.$file['path'].' successfully converted to: '.$translateToEncoding); } else { dump('File: '.$file['path'].' already converted to: '.$oldEncoding); } } } ?>