Building A Command Line App in PHP

Building A Command Line App in PHP

Tagged with showdev, php, cli, beginners. PHP is more than capable of building command line applications for use in Linux or macOS. Make a new directory cli-app. Building a command line app in PHP. The complete package from option handling to writing a man page.

The complete package from option handling to writing a man page

If you’re like me, you’re more comfortable writing simple scripts in PHP than C or Go or whatever language people are currently recommending. Fortunately, PHP is more than capable of producing command line apps for use in Linux or macOS.

In this tutorial, I’ll explain:

  • How to implement things like option handling and the environment in PHP.
  • Components of a command line app including things like a man page, config files, and so on.

As a minimum, you should be able to use these concepts and techniques to develop your own simple command line applications, in your language of choice.

I’ll be using excerpts from my program,  lingth, to demonstrate these concepts. (You might want to have  the source code open alongside this article as you read it.)

About the program, lingth

Lingth reports on lines that are longer than a certain number of characters. It’s useful for keeping to coding standards which, for example, specify an 80-character maximum.

By default, lingth reports lines longer than 80 characters. It prints line number, line, & length.

It’s simple enough to quickly understand, but complex enough to demonstrate several features of a command line program, including:

  • Configuration specified in a JSON file
  • Options specified via command line arguments
  • Input received via files or redirection
  • Error handling
  • Usage information

In addition, I’ll cover the inclusion of a man page and how to install everything.

unix php

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Hire PHP Developer - Best PHP Web Frameworks for Web Development

Hire our Laravel, CodeIgniter, YII, Zend, Cake PHP, Core PHP developers for your custom web development projects. Choose best PHP Web Frameworks & get satisfactory results.

Hire PHP Developer

Looking to develop a PHP based website from scratch or revamp your existing website? **[HourlyDeveloper.io](https://hourlydeveloper.io/ "HourlyDeveloper.io")** has always been an industry leader for companies and business owners looking to hire...

Noteworthy PHP Development Tools that a PHP Developer should know in 2021!

![This is image title](https://telegra.ph/file/856eae74f33107c93ca2c.jpg "This is image title") Hypertext Preprocessor, commonly known as PHP, happens to be one of the most widely used server-side scripting languages for developing web...

Top PHP web development company| PHP development services India

Are you looking for a php web development company? ValueCoders is a leading software company with 16+ years of experience offering PHP website development services to global clients. 4200+ projects | 2500+ Clients| 450+ Experts.

Custom PHP Development Company | PHP Web Development Service

One programming language that has its root in Website development even at present is PHP Website Development. The PHP programming is executed on the server side which means it functions on web servers which helps the website in its...