note 73526 added to function.ftell

From: Date: Tue, 27 Feb 2007 23:02:21 +0000
Subject: note 73526 added to function.ftell
Groups: php.notes 
Request: Send a blank email to php-notes+get-123936@lists.php.net to get a copy of this message
In response to php at michielvleugel dot com: This does not seem to be the case with PHP 5.2.0 and FreeBSD 5.4. #!/usr/local/bin/php <?php $tell = ftell(STDIN); var_dump($tell); ?> root@localhost:/home/david# echo Hello World | ./test.php int(0) root@localhost:/home/david# ./test.php int(6629927) When something is piped to the script, it returns an integer value of 0, however, it also returns an integer when nothing is piped to the script. The code should be modified to this: #!/usr/local/bin/php <?php $tell = ftell(STDIN); if ($tell === 0) echo "Something was piped: " . fread(STDIN,256) . "\n"; else echo "Nothing was piped\n"; ?> And the result is: root@localhost:/home/david# echo Hello World | ./test.php Something was piped: Hello World root@localhost:/home/david# ./test.php Nothing was piped ---- Server IP: 64.71.164.2 Probable Submitter: 69.2.234.66 ---- Manual Page -- http://www.php.net/manual/en/function.ftell.php Edit -- https://master.php.net/note/edit/73526 Del: integrated -- https://master.php.net/note/delete/73526/integrated Del: useless -- https://master.php.net/note/delete/73526/useless Del: bad code -- https://master.php.net/note/delete/73526/bad+code Del: spam -- https://master.php.net/note/delete/73526/spam Del: non-english -- https://master.php.net/note/delete/73526/non-english Del: in docs -- https://master.php.net/note/delete/73526/in+docs Del: other reasons-- https://master.php.net/note/delete/73526 Reject -- https://master.php.net/note/reject/73526 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#123936) next »