Skip to content

Instantly share code, notes, and snippets.

@Taluu
Created October 31, 2010 17:07
Show Gist options
  • Save Taluu/656838 to your computer and use it in GitHub Desktop.
Save Taluu/656838 to your computer and use it in GitHub Desktop.
Convert a ANSI file to an UTF8 file
<?php
/**
* Convertit un ensemble de fichiers de format ANSI en UTF8.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
* @package Talus' TPL
* @author Baptiste "Talus" Clavié <clavie.b@gmail.com>
* @copyright ©Talus, Talus' Works 2008, 2009
* @link http://www.talus-works.net Talus' Works
* @license http://www.gnu.org/licenses/gpl.html GNU Public License 2+
* @version $Id$
*/
// -- Voici les deux trois constantes à modifier :).
define('ROOT', './') ; // définir le répertoire à explorer ici.
define('EXT', '.html'); // Extension des fichiers à convertir
define('RECURSIVE', true); // Mode récursif ?
define('NOW', time());
function explore($dir){
if ($handle = opendir($dir)){
while (($file = readdir($handle)) !== false){
if ($file == '.' || $file == '..'){
continue;
}
if (is_dir(dirname($dir . '/' . $file) . '/' . $file) && RECURSIVE) {
explore(dirname($dir . '/' . $file) . '/' . $file . '/');
continue;
}
if( substr($file, -strlen(EXT)) == EXT ){
echo $file . ' ... ' . convert(dirname($dir . '/' . $file) . '/' . $file) . '<br />';
}
}
closedir($handle);
}
}
function convert($file){
$bytes = file_put_contents($file, utf8_encode(file_get_contents($file)));
@touch($file, NOW);
return $bytes ? 'Fait.' : 'Echec !';
}
explore(ROOT);
/** EOF /**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment