PHP 8.5.0 Alpha 1 available for testing

Voting

: two minus one?
(Example: nine)

The Note You're Voting On

hz_php at hotmail dot com { hussam alzahabi }
9 years ago
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/>";


}

}


}

?>

<< Back to user notes page

To Top