Created
April 11, 2012 16:40
-
-
Save f0t0n/2360436 to your computer and use it in GitHub Desktop.
dir. name to ascii
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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