Skip to content

Instantly share code, notes, and snippets.

@KrofDrakula
Created February 11, 2011 14:30
Show Gist options
  • Save KrofDrakula/822421 to your computer and use it in GitHub Desktop.
Save KrofDrakula/822421 to your computer and use it in GitHub Desktop.
<?php
function convertDir($directory, $target, $from, $to) {
$dir = opendir($directory);
while(false !== ($file = readdir($dir))) {
if(is_dir($file)) {
convertDir($directory . "/" + $file, $target . "/" . $file, $from, $to);
} else {
file_put_contents($target . "/" . $file, iconv($from, $to, file_get_contents($file)));
echo "Converted $file\n";
}
}
}
$dir = "/home/user/myphp";
$outpath = "/home/user/converted-php";
$fromCharset = "Windows-1250";
$toCharset = "UTF-8";
convertDir($dir, $outpath, $fromCharset, $toCharset);
echo "\n\n-------------------\nAll done!\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment