Created
January 15, 2013 20:15
-
-
Save hamidreza-s/4541622 to your computer and use it in GitHub Desktop.
List directory file/folder with PHP and create an array of them, then calculate their Character Code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" /> | |
</head> | |
<body> | |
<?php | |
// shell command | |
$list = shell_exec('ls'); | |
// split by newline | |
$listArray = preg_split('/\n|\r\n?/', $list); | |
// remove last index | |
array_pop($listArray); | |
// echo | |
foreach ($listArray as $item) | |
{ | |
echo 'File/Folder Name: ' . $item . '<br/>'; | |
echo 'Charset: ' . mb_detect_encoding($item) . '<br/>'; | |
echo 'Ascii: ' . string_to_ascii($item) . '<hr/>'; | |
} | |
// convert string to sum of its characters | |
function string_to_ascii($string) | |
{ | |
$ascii = NULL; | |
for ($i = 0; $i < strlen($string); $i++) | |
{ | |
$ascii .= ord($string[$i]) . ' '; | |
} | |
return $ascii; | |
} | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you can use of DirectoryIterator: http://php.net/manual/en/class.directoryiterator.php
like this: http://ideone.com/BAZ4IR