note 119237 added to function.opendir
| From: | hz_php at hotmail dot com{hussamalzahabi} | Date: | Sun, 24 Apr 2016 22:59:57 +0000 |
| Subject: | note 119237 added to function.opendir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-205315@lists.php.net to get a copy of this message | ||
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 = ("./"); // on this file dir
// detect if the path has arabic characters and use " u " optional to enable function to
match multibyte characters
if (preg_match('#[\x{0600}-\x{06FF}]#iu', $dir) )
{
// convert input ( utf-8 ) to output ( windows-1256 )
$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/>";
}
}
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 89.203.15.153
----
Manual Page -- http://php.net/manual/en/function.opendir.php
Edit -- https://master.php.net/note/edit/119237
Del: integrated -- https://master.php.net/note/delete/119237/integrated
Del: useless -- https://master.php.net/note/delete/119237/useless
Del: bad code -- https://master.php.net/note/delete/119237/bad+code
Del: spam -- https://master.php.net/note/delete/119237/spam
Del: non-english -- https://master.php.net/note/delete/119237/non-english
Del: in docs -- https://master.php.net/note/delete/119237/in+docs
Del: other reasons-- https://master.php.net/note/delete/119237
Reject -- https://master.php.net/note/reject/119237
Search -- https://master.php.net/manage/user-notes.php