The file directory operation of PHP surface question

Source: Internet
Author: User

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 string $filename The file name 1.jpg/1.png/1.html/1.php* to process  @return string. php/php  */function get_ Ext1 ($filename) {        return strrchr ($filename, '. ');} 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 ";

  

/*** Traversal Directory (Recursive) * @param string $dir directory name and finally no/* @return array $files Entire directory structure */function myscandir ($dir) {        $files = array (); C1/>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 file directory operation of PHP surface question

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.