示例#1
0
while (!$fileObject->isLast()) {
    echo $fileObject->nextLine();
    echo '<br/>';
}
echo '<br/>';
echo '<br/>';
echo 'Navigate:<br/>';
echo $fileObject->firstLine();
echo '<br/>';
echo $fileObject->nextLine();
echo '<br/>';
echo $fileObject->nextLine();
echo '<br/>';
echo $fileObject->firstLine();
echo '<br/>';
echo $fileObject->readLine(3);
echo '<br/>';
echo $fileObject->readLine(7);
echo '<br/>';
echo '<br/>';
echo '<br/>';
// read all
echo 'File Content:<br/>';
echo nl2br($fileObject->read());
echo '<br/>';
echo '<br/>';
echo '<br/>';
echo 'Array of lines:<br/>';
$lines = $fileObject->readLines();
// return array
foreach ($lines as $line) {
示例#2
0
 /**
  * @depends     testInit
  * @return      void
  */
 public function testIsLast()
 {
     $filePath = __DIR__ . '/example_read.txt';
     $fileObject = new FileReader($filePath, 'r', true);
     $this->assertEquals('Line08', $fileObject->readLine(7));
     $this->assertFalse($fileObject->isLast());
     $this->assertEquals('Line09', $fileObject->nextLine());
     $this->assertEquals('', $fileObject->nextLine());
     $this->assertTrue($fileObject->isLast());
     $fileObject = new \SplFileObject($filePath, 'r');
     $fileObject->setFlags(\SplFileObject::DROP_NEW_LINE | \SplFileObject::READ_AHEAD | \SplFileObject::SKIP_EMPTY);
     $fileObject->seek(7);
     $this->assertEquals('Line08', $fileObject->current());
     $this->assertFalse($fileObject->eof());
     $fileObject->next();
     $this->assertEquals('Line09', $fileObject->current());
     $fileObject->next();
     $this->assertEquals('', $fileObject->current());
     $this->assertTrue($fileObject->eof());
 }