note 65127 deleted from function.ssh2-exec by bjori
| From: | bjori@php.net | Date: | Mon, 24 Apr 2006 22:21:50 +0000 |
| Subject: | note 65127 deleted from function.ssh2-exec by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-109617@lists.php.net to get a copy of this message | ||
Note Submitter: Rene Samson
----
mao at nospam dot com made a typo in his initial code, that's why feof() doesn't seem to
work.
feof() (and other functions for a resource of type stream) work fine on the resource returned by
this function
The correct version of his initial example is:
<?php
$filename = "eg.txt";
$stream0 = ssh2_exec($conn, "stat $filename");
if($stream0) {
$i = 1;
// Notice the variable name is $stream0 and not $stream
while( !feof($stream0) ) {
$line = fgets($stream0) ;
echo "<br>Line $i ==> $line";
$i += 1;
}
?>
Also
<?php
while($line=fgets($stream0)){
}
?>
Won't work properly if you get an empty string back as part of the output, if you don't
want to use feof, but really want to use fgets in the while use this:
<?php
......
while(($line=fgets($stream0)) !== false){
echo "<br>Line $i ==> $line";
$i += 1;
}
?>