Chapter 16: Command-Line PHP Utilities (Web hosting reseller) 563 $keyboardBuffer =

Chapter 16: Command-Line PHP Utilities 563 $keyboardBuffer = null; if ($STDIN) { while(($ch = fgetc($STDIN)) != n ) { $keyboardBuffer .= $ch; } fclose($STDIN); } return $keyboardBuffer; } ?> The script calls a function called prompt(), which takes a string message and displays it on the shell screen. The prompt() function calls another function called getSTDIN(), which opens a file handle called $STDIN to /dev/stdin (i.e., php://stdin) and reads characters from it until a newline (n) character is entered by the user. This effectively gives us the command line entered by the user. The user- entered data is stored in a string buffer called $keyboardBuffer, which is returned to the caller of getSTDIN(). The PHP 4.3.x version of the command-line PHP binary with CLI enabled (–enable-cli) has STDIN, STDOUT, and STDERR constants predefined. These constants replace the following code: // STDIN constant replaces: $stdin = fopen( php://stdin , r ); // STDOUT constant replaces: $stdout = fopen( php://stdout , w ); // STDERR constant replaceS: $stderr = fopen( php://stderr , w ); Getting into arguments You will often need to get command-line arguments from the user. Listing 16-3 shows a simple script called arg.php, which prints out an array called $argv.

WordPress database error: [Table 'armadillowebhosting_com_-_jsp.wp_comments' doesn't exist]
SELECT * FROM wp_comments WHERE comment_post_ID = '619' AND comment_approved = '1' ORDER BY comment_date

Leave a Reply