PHP Code Statistics Tool

Source: Internet
Author: User

The tool is written in PHP, requiring files under the file to be PHP files (that is, files ending in. php), you can count the amount of PHP code in a folder, the code is as follows:

<?php$filename = "d:/code/";//php code Directory $counts = 0;function Codecount ($filename) {global $counts; $total = 0; Total number of rows $space = 0; Number of empty rows $notes = 0;    Note $handle = fopen ($filename, "R");    $isNotes = false;        while (! feof ($handle)) {$line = Fgets ($handle);        $total + +;            if ($isNotes) {$notes + +;            if (Preg_match ("/.* (\*\/)/", $line)) {//multi-line */comment end $isNotes = false;        } continue;        } if (Preg_match ("/^[\s]*$/", $line)) {//blank line $space + +;        } elseif (Preg_match ("/^[\s]*\/\//", $line)) {//two bar comment $notes + +;        } elseif (Preg_match ("/^[\s]* (\/\*). * (\*\/) [\s]*$/", $line)) {//single-line comment $notes + +;            } elseif (Preg_match ("/^[\s]* (\/\*). * *", $line)) {//Multiline//* Comments start $notes + +;        $isNotes = true; }} echo "Total:". $total.    "\ r \ n"; echo "Space:". $space.    "\ r \ n"; echo "notes:". $notes.    "\ r \ n"; echo "<bR> "; $counts + = ($total-$space-$notes);}  if (Is_file ($filename)) {codecount ($filename);} else if (Is_dir ($filename)) {if ($dh = Opendir ($filename)) {while ($file = Readdir ($DH))! = False) {//The full path of the file name contains the file name $filePath = $filena Me.                $file;                Gets the file modification time if (Is_file ($filePath)) {codecount ($filePath);        }} closedir ($DH); }}echo "<br>". $counts;//Output Total code volume?>




PHP Code Statistics Tool

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.