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";
?>
M:/SanDiegoWWW/www/dokuwiki/data/pages/san.php.cli/start.txt · Dernière modification: 2009/01/27 11:50 (modification externe)
 
Sauf mention contraire, le contenu de ce wiki est placé sous la licence suivante : CC Attribution-Noncommercial 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki