{"id":29,"date":"2015-03-01T00:07:53","date_gmt":"2015-02-28T16:07:53","guid":{"rendered":"http:\/\/blog.liangjinjin.cn\/?p=29"},"modified":"2015-04-03T23:02:40","modified_gmt":"2015-04-03T15:02:40","slug":"php%e5%88%97%e7%9b%ae%e5%bd%95%e4%bb%a3%e7%a0%81","status":"publish","type":"post","link":"https:\/\/blog.liangjinjin.cn\/?p=29","title":{"rendered":"PHP\u5217\u76ee\u5f55\u4ee3\u7801"},"content":{"rendered":"<div id=\"wpopt-ai-summary\"><\/div><pre class=\"prettyprint lang-php\">&lt;?php \n\/* \u51fd\u6570 listDirTree( $dirName = null ) \n** \u529f\u80fd \u5217\u51fa\u76ee\u5f55\u4e0b\u6240\u6709\u6587\u4ef6\u53ca\u5b50\u76ee\u5f55 \n** \u53c2\u6570 $dirName \u76ee\u5f55\u540d\u79f0 \n** \u8fd4\u56de \u76ee\u5f55\u7ed3\u6784\u6570\u7ec4 false\u4e3a\u5931\u8d25 \n*\/ \nfunction listDirTree( $dirName = null ) \n{ \nif( empty( $dirName ) ) \nexit( \"IBFileSystem: directory is empty.\" ); \nif( is_dir( $dirName ) ) \n{ \nif( $dh = opendir( $dirName ) ) \n{ \n$tree = array(); \nwhile( ( $file = readdir( $dh ) ) !== false ) \n{ \nif( $file != \".\" &amp;&amp; $file != \"..\" ) \n{ \n$filePath = $dirName . \"\/\" . $file; \nif( is_dir( $filePath ) ) \/\/\u4e3a\u76ee\u5f55,\u9012\u5f52 \n{ \n$tree[$file] = listDirTree( $filePath ); \n} \nelse \/\/\u4e3a\u6587\u4ef6,\u6dfb\u52a0\u5230\u5f53\u524d\u6570\u7ec4 \n{ \n$tree[] = $file; \n} \n} \n} \nclosedir( $dh ); \n} \nelse \n{ \nexit( \"IBFileSystem: can not open directory $dirName.\"); \n} \n\/\/\u8fd4\u56de\u5f53\u524d\u7684$tree \nreturn $tree; \n} \nelse \n{ \nexit( \"IBFileSystem: $dirName is not a directory.\"); \n} \n} \n$files = listDirTree(\".\"); \n\/\/print_r($files); \n$size = count(files); \n\/\/\u4ee5\u4e0b\u4ee3\u7801\u662f\u521b\u5efa\u4e00\u4e2a\u672c\u76ee\u5f55\u4e0b\u6587\u4ef6\u7684\u5217\u8868\uff08\u5e26\u6709\u94fe\u63a5\u5730\u5740\uff09 \necho '&lt;ol&gt;'; \nfor( $i=0; $files[$i] != NULL; $i++ ) { \necho '&lt;li&gt;&lt;a href=\"'.($files[$i]).'\" target=\"_blank\"&gt;'.$files[$i].'&lt;\/a&gt;&lt;\/li&gt;'; \n} \necho '&lt;\/ol&gt;'; \n?&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&lt;?php \/* \u51fd\u6570 listDirTree( $dirName = null ) ** \u529f\u80fd \u5217\u51fa\u76ee [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[21,22],"class_list":["post-29","post","type-post","status-publish","format-standard","hentry","category-23","tag-php"],"_links":{"self":[{"href":"https:\/\/blog.liangjinjin.cn\/index.php?rest_route=\/wp\/v2\/posts\/29","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.liangjinjin.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.liangjinjin.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.liangjinjin.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.liangjinjin.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=29"}],"version-history":[{"count":0,"href":"https:\/\/blog.liangjinjin.cn\/index.php?rest_route=\/wp\/v2\/posts\/29\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.liangjinjin.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=29"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.liangjinjin.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=29"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.liangjinjin.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=29"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}