Browse File artifacts! The number of lines in all file codes can be calculated!

Source: Internet
Author: User
This class lists the details of a file and counts the total code lines in a directory. You can modify the file type to be counted based on your needs. You can also limit the statistical type var $ extarray (php, phtml, php3, inc, js, html, htm, css, doc); Code: www.codepearl.comfiles198.html PHP source code and demo: source code

This class lists the details of a file and counts the total code lines in a directory. You can modify the file type to be counted based on your needs. You can also limit the statistical type var $ ext = array (php, phtml, php3, inc, js, html, htm, css, doc); Code pearl: http://www.codepearl.com/files/198.html PHP source code and demo: source code

This class lists the details of a file and counts the total code lines in a directory. You can modify the file type to be counted based on your needs.

You can also limit the statistical type.
Var $ ext = array ("php", "phtml", "php3", "inc", "js", "html", "htm", "css ", "doc ");
Code pearl: http://www.codepearl.com/files/198.html PHP

Source code and demo:Source code source demonstration Source

 Source Code Count
 dir="../linecount";// Use this method to output the summary and list of files to the page// You can customize the HTML from within the class$lineCount->summary(1);// Use this method to get the totals as an associative array:$totals = $lineCount->summary(0);# echo $totals["folders"] / $totals["files"] / $totals["lines"]?>
 CountLines ($ filePath);} else {// Item is a file, get some info about it $ fileName = explode ("/", $ filePath ); $ fileDir = $ fileName [(count ($ fileName)-2)]; $ fileName = $ fileName [(count ($ fileName)-1)]; $ fileExt = explode (". ", $ fileName); $ fileExt = $ fileExt [(count ($ fileExt)-1)]; if (in_array ($ fileExt, $ this-> ext )) {// Open the file, get line count $ fp = fopen ($ filePath, "r"); $ buffer = rawurlencode (fread ($ fp, fil Esize ($ filePath); $ buffer = explode ("% 0A", $ buffer); $ numLines = count ($ buffer); fclose ($ fp ); // Add the information to our count array $ this-> cnt [$ this-> x] ['dir'] = $ dir; $ this-> cnt [$ this-> x] ['file'] = $ fileName; $ this-> cnt [$ this-> x] ['Count'] = $ numLines; $ this-> x ++ ;}}} closedir ($ handle );} else {return false ;}} function summary ($ output = 1) {// $ output // 1 to generate a summary and File list // 0 to get an associative array with the totalsif (! (Is_dir ($ this-> dir) {// No directory given, use document root $ this-> dir = $ _ SERVER ['document _ root'];} $ this-> countLines ($ this-> dir); $ listOutput = ""; $ totalLines = 0; $ usedDir = array (); for ($ I = 0; $ I
 
  
Cnt); $ I ++) {$ totalLines + = $ this-> cnt [$ I] ['Count']; if (! (In_array ($ this-> cnt [$ I] ['dir'], $ usedDir) {if ($ output = 1) {$ listOutput. ="\ N "; $ listOutput. ="
  ". Iconv (" GB2312 "," UTF-8 ", $ this-> cnt [$ I] ['dir'])."\ N "; $ listOutput. ="\ N ";}$ usedDir [] = $ this-> cnt [$ I] ['dir'];} if ($ output = 1) {$ listOutput. ="\ N "; $ listOutput. ="". Iconv (" GB2312 "," UTF-8 ", $ this-> cnt [$ I] ['file'])."\ N "; $ listOutput. ="". Number_format ($ this-> cnt [$ I] ['Count'])."\ N "; $ listOutput. ="\ N ";}}$ totalFiles = number_format (count ($ this-> cnt); $ totalLines = number_format ($ totalLines ); $ totalFolders = number_format (count ($ usedDir); if ($ output = 1) {print"
  
   
\ N "; print"
   ". $ This-> dir ."
   

\ N "; print" \ N "; print" \ N "; print" \ N "; print" \ N "; print"
Brief description:". $ TotalFolders." folder, ". $ totalFiles." file, ". $ totalLines." line code
\ N "; print" \ N "; print" \ N "; print" \ N "; print" \ N "; print" \ N "; print $ listOutput; print"
File Name/directoryNumber of lines of code
\ N "; print" \ N "; print" \ N "; print" \ N "; print" \ N "; print"
Brief description:". $ TotalFolders." folder, ". $ totalFiles." file, ". $ totalLines." line code
\ N "; print" \ N ";}else {return array (" files "=>$ totalFiles," lines "=>$ totalLines," folders "=>$ totalFolders) ;}}}?>

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.