188 Chapter 5 Basic Web Application Strategies Listing 5.2 Continued { $body .= fgets($fp, 64); } fclose($fp); // Mail the message to all specified recipients for($i=2; $i chmod +x script.php tobias@dev:/home/tobias/ > ./script.php On Windows, you can associate the file extension .php with the interpreter to achieve the same result. The script shows two important concepts often needed in command-line scripts: accessing arguments passed to the script and reading from standard input. PHP automatically sets up an array named $argv that contains the script s filename as first entry and as subsequent entries all arguments to the script.This is actually the same behavior as in C. Just as in C, there s another variable, $argc, containing the number of arguments. Of course, you can also use count($argv). For example, if you call a PHP script with php script.php3 foo, $argv[1] would contain the first argument, foo. The other noteworthy part of the code is reading from standard input. PHP 4.0 allows you to use so-called PHP streams with fopen().To accept user input on the command line or read in data passed from another program, php://stdin is used.The script uses it to read the log message provided by CVS; you could also prompt for user input with a similar function. Listing 5.3 shows it in action.
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Inexpensive Web Hosting services
No comments yet.
Sorry, the comment form is closed at this time.