PHP

PHP-CLI Introduction-Part-One

PHP CLI? What kinda food is that? Don’t get mad with any “PHP variation” because PHP-CLI is a very simple thing.

CLI stands from Command Line Interface. That means PHP that run from command line. You can mention MS DOS in Windows or console/shell in Linux platform. No need web server anymore because we aren’t going to make a web. We will use it to create desktop applications.

First step, identify your PHP installation. Where did you install PHP on your machine? Linux user just need to write:

$ whereis php

and system will tell you where is PHP living in your machine.

Second step, let’s create the world’s famous programmer’s phrase:


< ?php // name it test.php echo "Hello World!"; ?>


and save it at the same directory as your PHP installation. It’s not a must, just to ease our practise.

Then, the moment we are waiting for. Executing the script!

C:php4>php.exe test.php [enter]
Hello World!

of course we do the same in linux:

$ php test.php [enter]
Hello World!

Our third step is reading user’s input. We won’t create a selfish application, right? There will be two variables passed by the command line: $argv and $argc.

$argv is an array containing all parameters passed on the command line with space as the delimiters. While $argc is the number of total $argv array.


< ?php // name it test2.php print_r($argv); ?>

Let’s see what will appear in the next post ^_*

2 Comments

  1. comment should work now!

  2. wah artikelnya dah lama juga yak… tapi tetap repot kalo nge-post .. 😀 atau nge-get 😀

Leave a Reply