http://php.net/manual/en/features.commandline.options.php ------------------------------------------ -r <code> Run PHP <code> without using script tags <?..?>
例:php
1. cat xxx.log | php -r 'echo stream_get_contents(STDIN)."\n";'this
// STDIN is just a shortcut of $fh = fopen("php://stdin", "r"); spa
2. cat access.log | php -r 'echo readfile("php://stdin")."\n";'.net
3. read by line:
cat access.log | php -r 'while (!feof(STDIN)){ echo fgets(STDIN); };'code
---------------------------------------ip
-R <code> Run PHP <code> for every input line
-R | --process-code | PHP code to execute for every input line. Added in PHP 5.ci There are two special variables available in this mode: $argn and $argi. $argn will contain the line PHP is processing at that moment, while $argi will contain the line number.get |
例:input
cat /xxx.log | php -R 'echo $argi . ":" . $argn . "\n";'it
============================
-f <file> Parse and execute <file>.
-F <file> Parse and execute <file> for every input line
例:
If you want it to show up in $argv
, try this:
echo "Whatever you want" | xargs php script.php
That would covert whatever goes into standard input into command line arguments.
=================================
http://stackoverflow.com/questions/5891888/piping-data-into-command-line-php