This problem is not difficult in fact, the test center is mainly in the function substr () STRRCHR () Array_pop () Strrpos () Strpos () Strrev () explode () PathInfo ().
Not much nonsense to say, directly to everyone put the code.
Get file suffix, traverse directory hierarchy
/*** 5 ways to get the file suffix name * This problem is actually the test function substr () STRRCHR () Array_pop () Strrpos () Strpos () Strrev () explode () pathinfo () * @param strin G $filename the file name to process 1.jpg/1.png/1.html/1.php* @return string. php/php */function Get_ext1 ($filename) {return STRRCHR ($f Ilename, '. ');} function Get_ext2 ($filename) {return substr ($filename, Strrpos ($filename, '. '));} function Get_ext3 ($filename) {return Array_pop (Explode ('. ', $filename));} function Get_ext4 ($filename) {return pathinfo ($filename, pathinfo_extension);} function Get_ext5 ($filename) {return Strrev (substr (Strrev ($filename), 0,strpos (Strrev ($filename), '. ')));} $filename = "1.php"; Echo get_ext1 ($filename). " \ n "; Echo get_ext2 ($filename)." \ n "; Echo get_ext3 ($filename)." \ n "; Echo Get_ext4 ($filename)." \ n "; Echo get_ext5 ($filename)." \ n ";/*** traverse Directory (Recursive) * @param string $dir directory name and finally no/* @return array $files Entire directory structure */function myscandir ($dir) {$files = array ( ); if ($handle = Opendir ($dir)) {while (($file = Readdir ($handle)) = False) {if ($file! = ". "&& $file! =" ... ") {$newDir = $dir. " /". $file; if (Is_dir ($newDir)) {$files [$file] = Myscandir ($newDir); }else{$files [] = $file; }}} closedir ($handle); return $files; }} $dir = "/dirname";p Rint_r (Myscandir ($dir));
The above code is not very simple ah, on these functions, functions mastered, the problem is easy to solve, I hope this article to share to help you.