views:

993

answers:

2

Hi there

I'm just curious. Do you know any tool which can count all the code lines from a PHP project?

Many thx!

+10  A: 

On a POSIX operating system (e.g. Linux or OS X) you can write the following into your Bash shell:

wc -l `find . -iname "*.php"`

This will count the lines in all php-files in the current directory and also subdirectories. (Note that those single 'quotes' are backticks, not actual single quotes)

Henrik Paul
And if you are on Windows, you can download and install Cygwin, and do likewise. Since Mac runs on top of a BSD OS now as well, I consider this the definitive answer.
George Jempty
Keep in mind if you've got a lot of PHP template files and/or other PHP files with mixed PHP/HTML code, this isn't going to exclude HTML only lines.
Alan Storm
+4  A: 

SLOCCount is an awesome tool that produces a line-count report for a large number of languages. It also goes further by producing other, related statistics such as expected developer cost.

Here's an example:

$ sloccount .
Creating filelist for experimental
Creating filelist for prototype
Categorizing files.
Finding a working MD5 command....
Found a working MD5 command.
Computing results.


SLOC    Directory SLOC-by-Language (Sorted)
10965   experimental    cpp=5116,ansic=4976,python=873
832     prototype       cpp=518,tcl=314


Totals grouped by language (dominant language first):
cpp:           5634 (47.76%)
ansic:         4976 (42.18%)
python:         873 (7.40%)
tcl:            314 (2.66%)




Total Physical Source Lines of Code (SLOC)                = 11,797
Development Effort Estimate, Person-Years (Person-Months) = 2.67 (32.03)
 (Basic COCOMO model, Person-Months = 2.4 * (KSLOC**1.05))
Schedule Estimate, Years (Months)                         = 0.78 (9.33)
 (Basic COCOMO model, Months = 2.5 * (person-months**0.38))
Estimated Average Number of Developers (Effort/Schedule)  = 3.43
Total Estimated Cost to Develop                           = $ 360,580
 (average salary = $56,286/year, overhead = 2.40).
SLOCCount, Copyright (C) 2001-2004 David A. Wheeler
SLOCCount is Open Source Software/Free Software, licensed under the GNU GPL.
SLOCCount comes with ABSOLUTELY NO WARRANTY, and you are welcome to
redistribute it under certain conditions as specified by the GNU GPL license;
see the documentation for details.
Please credit this data as "generated using David A. Wheeler's 'SLOCCount'."
marcog