Assuming you've already gotten a list of folders on the server (via while()
loop or glob()
function) and this list is stored in $folderList[]
, I'd try something like the following if you're just outputting the result:
$a = array(...);
$e = array(...);
$i = array(...);
$o = array('Ò','Ó','Ô','Õ','Ö','ò','ó','ô','õ','ö');
$u = array(...);
foreach($folderList as $folder){
$folder = str_replace($a,"a",$folder);
$folder = str_replace($e,"e",$folder);
$folder = str_replace($i,"i",$folder);
$folder = str_replace($o,"o",$folder);
$folder = str_replace($u,"u",$folder);
}
It's fairly sloppy, but it's also fairly simple. If you wanted something that would run quicker you'd be looking at doing math or comparisons with the binary value of the unicode. For instance, everything in the $o
array is the unicode characters 00D2 to 00D6 and 00F2 to 00F6. So if the letter is between dechex('00D2')
and dechex('00D6')
OR that letter is between dechex('00F2')
and dechex('00F6')
then replace it with "o".
If you're getting the value without the special characters (such as via URL post) and you want to map it to a folder, then you have to take a slightly different approach. First, realize that this isn't the ideal solution since you may have two folders, one named Òdla
, one named Ödla
. In this case, the search phrase odla
could only refer to one of these folders. The other would be permanently ignored. Assuming you're fine with this (such as: you can guarantee that there will be no such duplicate folder names), you would probably want to use GLOB_BRACE
.
<?php
$vowels = array("a", "e", "i", "o", "u");
$replace = array("...", "...", "...", "{Ò,Ó,Ô,Õ,Ö,ò,ó,ô,õ,ö}", "...");
$search = "odla";
$search = str_replace($vowels, $replace, $search);
// Returns every folder who matches "Òdla", "Ódla", "Ôdla"....
glob($search, GLOB_BRACE);
?>