Good question. The behavior you want is clearly expressed by the syntax you used. I think this is a mistake. You can probably report this at
http://bugs.php.net . The stream must be processed internally without rewinding and caching.
Be careful! The solution with SplFileObject is more than wild.
NoRewind is required to prohibit rewinding. Then Cache is needed to store the contents of the stream inside and makes it viewable. Then LimitIterator is needed to search for line 200.
Here we go:
$obj = new SplFileObject("zip://archive.zip#file.txt"); $norewind = new NoRewindIterator($obj); $caching = new CachingIterator($norewind); $limit = new LimitIterator($caching, 200, 1); foreach ($limit as $i => $line) { printf("%03d: %s", $i, $line); }
source share