PHPBuilder - Piping output into your PHP scripts

RSS Twitter
Tips Tricks And Hacks

Piping output into your PHP scripts

by: Joe Stump
September 12, 2000

Here is a dirty little trick that lets you pipe output from grep, sed, awk, perl, etc. into your PHP scripts

#!/usr/local/bin/php -q

$fp = fopen('/dev/stdin','r+');
$n = 1;
    $line = trim(fgets($fp,4096));
     // do stuff to line here
     echo $n.' ==> '.$line."\n";


Now you can do something like this: "ls -alF | output.php" after you have "chmod +x outputl.php"

This is extremely useful when you need to do log processing, etc. on different boxes and you may need to parse it differently on each box. You can merely cat file.txt | output.php and presto you have output to stdout.

Comment and Contribute

Your comment has been submitted and is pending approval.

Joe Stump



(Maximum characters: 1200). You have characters left.