note 121112 added to splfileobject.construct

From: Date: Mon, 22 May 2017 16:24:24 +0000
Subject: note 121112 added to splfileobject.construct
Groups: php.notes 
Request: Send a blank email to php-notes+get-209094@lists.php.net to get a copy of this message
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. ---- Server IP: 72.52.91.14 Probable Submitter: 122.219.244.225 ---- Manual Page -- http://php.net/manual/en/splfileobject.construct.php Edit -- https://master.php.net/note/edit/121112 Del: integrated -- https://master.php.net/note/delete/121112/integrated Del: useless -- https://master.php.net/note/delete/121112/useless Del: bad code -- https://master.php.net/note/delete/121112/bad+code Del: spam -- https://master.php.net/note/delete/121112/spam Del: non-english -- https://master.php.net/note/delete/121112/non-english Del: in docs -- https://master.php.net/note/delete/121112/in+docs Del: other reasons-- https://master.php.net/note/delete/121112 Reject -- https://master.php.net/note/reject/121112 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#209094) next »