Reply to Re: thought stdin was supposed to default open

Your name:

Reply:


Posted by "M. Sokolewicz" on 01/08/06 11:46

matt V wrote:
> hello,
> I read that in the cli version of php, the 3 files, sterror, stdout and
> stdin are already open thus saving having to open them and close them
> each time. Well, I decided to test that idea and it appears that stdin
> infact is not pre-opened, but my code may be wrong too, who knows.
> I made a little test script (see below), but either it ends up
> outputting nothing, or i get the "... assumed 'STDIN'" and "supplied
> argument is not a valid resource...." but on the same line.
> anyway, code is below
>
> <?php
> while(STDIN != '\n');
> {
> $line = fgets(STDIN);
> echo $line;
> }
> ?>
>
you DO understand that STDIN is a resource and (unlike Perl,) PHP can't
compare a string to a resource! Next, you're comparing to '\n', note the
single quotes; you're not comparing to the newline char, you're
comparing to a \ followed by an n literally.
So..., your code will spit out errors for sure.

while(($line = fgets(STDIN)) != "\n");
{
echo $line;
}
would work though, and have the same functionality you tried to achieve
in your above code.

> simple script, but it appears not to work. is it my code, or is STDIN
> not opened by default in php4.4
> this is on slackware linux version 10.2 running php -v 4.4
> matt

it is opened, but you need to use it correctly to get there ;)
- tul

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация