September 25, 2005

Learing the difference between php://output and php://stdout

it took me way too long to figure out the difference between php://ouput and php://sdtout. looking at the wrappers page it seems like they both should do the same thing. you can run this little script to see the difference.
<?php
$fo = fopen('php://output', 'w');
$fs = fopen('php://stdout', 'w');

fputs($fo, "You can see this with the CLI and Apache.\n");
fputs($fs, "This only shows up on the CLI...\n");

fclose($fo);
fclose($fs);
?>
Posted by drewish at 01:03 AM | Comments (0) | TrackBack

piping php one-liners

When you're writing one line php scripts remember that 'php://stdin' is your friend. Here's a simple program I use to format PHP code for inclusion on my blog:

UNIX:
cat test.php | php -r "print htmlentities(file_get_contents('php://stdin'));"

DOS/Windows:
type test.php | php -r "print htmlentities(file_get_contents('php://stdin'));"

Posted by drewish at 12:48 AM | Comments (0)

September 07, 2005

showing the source

want a directory full of php files to be showns as source instead of being interpreted? don't want to rename every one from *.php to *.phps? then apache's forcetype directive is for you. drop this little baby into your .htaccess file and you'll be good to go.

<FilesMatch "\.(php)$">
    ForceType application/x-httpd-php-source
</FilesMatch>

Posted by drewish at 12:53 PM | Comments (0) | TrackBack
Creative Commons License xml feed