9

In particular, I am interested to know how many lines of codes there are, but this spans across many files.

I have been using notepad++ to author the code and for each file it does display line numbers but of course I have empty returns to make the code more readable.

Does anyone know of a plugin or tool that I can accurately get the actual lines of code?

Michal M
  • 9,322
  • 8
  • 47
  • 63
Harry
  • 91
  • 1
  • 2
  • 1
    Using PHP Designer or Dreaweaver would be a better alternative.... – Prasoon Saurav Jun 24 '10 at 11:51
  • You might take a look at this previous answer http://stackoverflow.com/questions/1300420/good-php-metric-tools though counting the number of lines of code isn't really a significant measure of anything – Mark Baker Jun 24 '10 at 12:24
  • @Jens: The OP clearly thought his line count spanned multiple files. The only thing I can imagine he might want to do that is to count the apparant size of a PHP script including the code participating via the transitive closure of a require (aka "include") clause, then it has to be PHP specific. That's sort of a measure of how hard it is to comprehend a script, because requires clauses are typically used to import what amounts to APIs and their implementation. Harry, please comment? – Ira Baxter Jul 12 '10 at 02:07

3 Answers3

24
  1. Go to Search -> Find in Files... or use Ctrl+Shift+F

    https://i.stack.imgur.com/V5MKW.png

  2. Find what: \S+\s*\r\n

    Filters: *.php

    Search Mode Regular expression

    Click Find All

    https://i.stack.imgur.com/YRXUX.png

  3. See the 'Find result' in the lower pane

    i.stack.imgur.com/UpuAQ.png

It's not perfect at all, but it works out of the box. Of course you can also make changes to the regular expression, like only counting lines with:

  • White space only: ^\s*\r\n
  • At least one letter or number: \w+.*\r\n
  • Which are used solely for curly braces: ^(\s*[{}]\s*)+\r\n
  • A class keyword: class .*\r\n
  • A function keyword: function .*\r\n
bwb
  • 396
  • 2
  • 4
  • 1
    [@quamrana](http://stackoverflow.com/users/4834/quamrana) thanks for embedding the images. – bwb Jun 22 '13 at 20:03
2

Google for "php sloc counter". There are plenty of tools to do that, for example:

http://thecodecentral.com/2007/12/26/source-line-of-code-counter

However, this kind of measuring is absolutely useless, so I'm not sure why you would want to do this.

houbysoft
  • 32,532
  • 24
  • 103
  • 156
1

Linux:

find -name '*.php' | xargs grep -av '\r' | wc -l

Windows (PowerShell):

(dir -include *.php -recurse | select-string "(?!^$)").count
silent
  • 3,843
  • 23
  • 29