CakeFest 2025 Madrid: The Official CakePHP Conference

Voting

: min(nine, one)?
(Example: nine)

The Note You're Voting On

KEINOS at blog.keinos.com
8 years ago
When using URL as a filename, such as "http://..." or "php://stdin", and also have the fopen wappers on, and you get a 'RuntimeException' error, try using "NoRewindIterator" class to a SplFileObject instance.

<?php
$url
= 'http://sample.com/data.csv';
$file = new NoRewindIterator( new SplFileObject( $url ) );
foreach (
$file as $line_num => $line) {
echo
"Line $line_num is $line";
}
?>

While opening a file, a rewind method will be called, but these URL iterators cannot be rewind, so you'll get a "Fatal error: Uncaught exception 'RuntimeException' with message 'Cannot rewind file ...'" error.

<< Back to user notes page

To Top