Searching for files in a directory

There is a php script that reads the name of the files in the folder (the name is translit in Latin) and translates them into Russian. How to search in a folder, taking into account what will be searched in Russian?

For clarity, the code:

<?php  
if ($handle = opendir('.')) {  
    while (false !== ($file = readdir($handle))) {  
        if ($file != "." && $file != "..") {  
            $files[] = $file;  
        }  
    }  
    closedir($handle);  
}  
/* config */  
$COUNT_FILES_ON_PAGE = 37;  
###  
$COUNT_FIELES = count($files);  
$COUNT_PAGES = intval($COUNT_FIELES / $COUNT_FILES_ON_PAGE);  
if(empty($_GET['p']) || $_GET['p'] < 0 || $_GET['p'] > $COUNT_PAGES || !intval($_GET['p']))  
$_GET['p'] = 0;
echo '<h2>  : '.$COUNT_FIELES.'</h2>';  
echo '   : <b>'.($COUNT_PAGES +1).'</b><br>';  
echo '  : <b>'.$COUNT_FILES_ON_PAGE.'</b><br>';;  
echo ' : <b>'.($_GET['p']+1).'</b><br>';  
echo '<br><center><strong>          (Download Master)</strong></center><br>';
for ($i=0; $i<= $COUNT_PAGES;$i++) {  
echo '<a href="?p='.$i.'">['.($i+1).']</a> '; 
}  
echo '<hr>';
$START = $_GET['p'] * $COUNT_FILES_ON_PAGE;  
$END = $START + $COUNT_FILES_ON_PAGE;
for ($i = $START; $i < $END; $i++) {
if(key_exists($i,$files)) {  
if(is_file('.'.$files[$i]))
$cat = "$files[$i]";  //,   
$r=array("yo","ye","ts","ch","sh","shch","yu","ya","a","b","v","g","d","e","j","z","i","y","k","l","m","n","o","p","r","s","t","u","f","e","_","h","w");           //   "a" ?b");
$r2=array("","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""," ","","");          //    "0" ?1");
$trans = str_ireplace($r,$r2,$cat);
echo '<img src="/images/PostCategoryIcon.png" WIDTH="50" HEIGHT="50" alt=""><a href="/gitara/tabs_ru/'.$cat.'" title="'.$trans.'  ">: '.$trans.'</a><br>';
if(is_dir('.'.$files[$i]))
echo $files[$i].' - [DIR]<br>';  
}       
}
?>

Answer 1, authority 100%

You can try to translate the query in Russian back into Latin transliteration and use it as a query for which to search. You already have the corresponding characters, you just need to translate them back from Russian into Latin.

Leave a reply

Please enter your comment!
Please enter your name here