php 文件总结

WBOY
Release: 2016-06-23 14:30:52
Original
1025 people have browsed it

通过一下代码,总结php文件函数

// current directoryecho getcwd() . "\n";chdir('hhh');// current directoryecho getcwd() . "\n";
Copy after login

D:\xampp\htdocs\my\function
D:\xampp\htdocs\my\function\hhh

$dir = 'D:\xampp\htdocs\my\function';// Open a known directory, read directory into variable and then closeif (is_dir($dir)) { if ($dh = opendir($dir)) { $ds = array(); while ($directory = readdir($dh)) { $ds[] = $directory; } rewinddir($dh); while ($directory = readdir($dh)) { $ds[] = $directory; } closedir($dh); }}print_r($ds);
Copy after login

Array ( [0] => . [1] => .. [2] => file.php [3] => hhh [4] => . [5] => .. [6] => file.php [7] => hhh )

$dir = 'D:\xampp\htdocs\my\function';showfiles3($dir);function showfiles1($dir){ if (is_dir($dir)) { echo "
    "; $dh = opendir($dir); while ($file = readdir($dh)) { if (is_dir($dir.DIRECTORY_SEPARATOR.$file)) { if ($file !='.' && $file != '..') { echo "
  • "; echo "|-".$file; showfiles1($dir.DIRECTORY_SEPARATOR.$file); echo "
  • "; } } else{ echo "
  • "; echo "--".$file; echo "
  • "; } } closedir($dh); echo "
"; }}function showfiles2($dir){ echo "
    "; $arr = scandir($dir); foreach ($arr as $file) { if (is_dir($dir.DIRECTORY_SEPARATOR.$file)) { if ($file !='.' && $file != '..') { echo "
  • "; echo "|-".$file; showfiles2($dir.DIRECTORY_SEPARATOR.$file); echo "
  • "; } } else{ echo "
  • "; echo "--".$file; echo "
  • "; } } echo "
";}function showfiles3($dir) { foreach (glob($dir.DIRECTORY_SEPARATOR.'*') as $f) { echo is_dir($f) ? showfiles3($f) : "$f
"; }}
Copy after login

$dir = 'D:\xampp\htdocs\my\function';$d = scandir($dir, 1);print_r($d);
Copy after login

Array ( [0] => hhh [1] => file.php [2] => .. [3] => . )

//目录的检索函数glob()//检索当前目录下所有"*.txt"的文件$files = glob("*.txt");//检索当前目录下所有以"t"开头的子目录$files = glob("t*",GLOB_ONLYDIR);//检索当前目录下所有以"d,t或p"开头的php文件$files = glob("{d,t,p}*.php",GLOB_BRACE);
Copy after login

一点小疑问:.文件 和 ..文件的详细分析




Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!