Categories
PHP

PHP CLI “Hello World”

I have only recently begun working with PHP CLI scripts.

Executing PHP scripts from the command line is fairly easy and you require no extra knowledge to create a basic script. As you progress you will need to know some new methods of using PHP.

Below is a PHP script called hello.php which is executed from the command line and takes one optional argument:

<?php
if ($argc !== 2) {
    echo "Usage: php hello.php [name].\n";
    exit(1);
}
$name = $argv[1];
echo "Hello, $name\n";

From the command line, issue the command:
php hello.php yourname

By foxbeefly

PHP / MySQL Developer

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.