PHP CLI

Sur Unix

Ecrire dans un fichier test.php (chmod 755 test.php):

#!/usr/bin/php -q
ou
#!/opt/bin/php -q
<?php
echo "Test Arguments:\n";
echo $_SERVER["argc"]."\n";
echo $_SERVER["argv"][0]."\n";
?>

Sur Windows

#!C:\Program Files\php\php.exe -q
ou
#!L:\xampp\php\php.exe -q

<?php
/* Define STDIN in case if it is not already defined by PHP for some reason */
if(!defined("STDIN")) {
define("STDIN", fopen('php://stdin','r'))
}
 
echo "Hello! What is your name (enter below):\n";
$strName = fread(STDIN, 80); // Read up to 80 characters or a newline
echo 'Hello ' , $strName , "\n";
?>