Sometimes the programmer needs to access folder content which has arabic name but the opendir function will return null resources id
for that we must convert the dirname charset from utf-8 to windows-1256 by the iconv function just if the preg_match function detect arabic characters and use " U " additionality to enable multibyte matching
<?php
$dir = ("./"); if (preg_match('#[\x{0600}-\x{06FF}]#iu', $dir) )
{
$dir = iconv("utf-8","windows-1256",$dir);
}
if( is_dir($dir) )
{
if( ( $dh = opendir($dir) ) !== null )
{
while ( ( $file = readdir($dh) ) !== false )
{
echo "filename: ".$file ." filetype : ".filetype($dir.$file)."<br/>";
}
}
}
?>