Skip to content

Instantly share code, notes, and snippets.

@f0t0n
Created April 11, 2012 16:40
Show Gist options
  • Save f0t0n/2360436 to your computer and use it in GitHub Desktop.
Save f0t0n/2360436 to your computer and use it in GitHub Desktop.
dir. name to ascii
<?php
header('Content-Type: text/plain; charset=ISO-8859-1');
ini_set('memory_limit', '512M');
ini_set('max_execution_time', '0');
defined('DS') OR define('DS', DIRECTORY_SEPARATOR);
setlocale(LC_ALL, 'en_US.ISO-8859-1');
function clearUTF($s) {
$r = '';
$s1 = iconv('ISO-8859-1', 'ASCII//TRANSLIT', $s);
for ($i = 0; $i < strlen($s1); $i++) {
$ch1 = $s1[$i];
$ch2 = mb_substr($s, $i, 1);
$r .= $ch1=='?'?$ch2:$ch1;
}
return $r;
}
function _2Ascii($dir) {
$items = scandir($dir);
$dirIgnore = array('.','..');
foreach($items as $item) {
if(in_array($item,$dirIgnore))
continue;
$oldName = $dir.DS.$item;
$newName = $dir.DS.clearUTF($item);
@rename($oldName, $newName);
if(is_dir($newName))
_2Ascii($newName);
}
}
$dir = dirname(__FILE__).DS.'resources'.DS.'export';
_2Ascii($dir);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment