Lingth is a “simple line-length checker” — it checks for long lines in a file. This can be useful for enforcing line lengths as part of coding guidelines, but the command has general applications (see Examples).

It should be straightforward to add to a git hook and enforce line length throughout a project.

Apart from being very limited, this code is a pretty decent example of a small command-line app, written in php. It does all the flag-parsing, handling of multiple files, redirected input, etc. itself, but it’s still a very small codebase. This makes it good as a template for other work, or as an introduction to the language.


lingth *.php

Report any long lines (currently, longer than 80 chars) from all files ending ‘.php’.

lingth -m22 /usr/share/dict/words

Get a list of words longer than 22 characters. (On my own system, there are exactly 22 words longer than 22 characters, all 23 or 24 characters long. “anthropomorphologically” is 23)

echo foo | lingth -hln -m 2

Print ‘foo’, and nothing else, so long as ‘foo’ is longer than 2 characters (which it is!).

echo '😊' | lingth -n -m 0

Confirm the length of a single emoji character is just 1 (line length is in the output).


You can read more about lingth in Building a command line app in PHP, an article I wrote explaning best practices for Unix commands and how you can implement them.


The project page is on GitHub; I welcome all bug reports and patches, but I’m not intending on adding any features to this software; it’s intended to stay pretty much the same, for now.