note 42648 added to function.fscanf

From: Date: Tue, 25 May 2004 11:03:55 +0000
Subject: note 42648 added to function.fscanf
Groups: php.notes 
Request: Send a blank email to php-notes+get-70053@lists.php.net to get a copy of this message
I have a simpler method I use to parse delimited text. Using the data posted by gozer at fanhunter dot com, here is my script. Maybe it is faster? <?php $fp = fopen ("sections.dat","r"); if (!$fp) {echo "<p>Unable to open remote file.</p>"; exit;} while (!feof($fp)): $line = fgets($fp, 2048); $out = array($line); list ($id, $name, $description, $language, $directory, $id_uplevel, $order, $hassubsection) = split ("\|", $out[0]); echo "$id-$name-$description-$language-$directory- $id_uplevel-$order-$hassubsection<br />\n"; $fp++; endwhile; fclose($fp); ?> Notes: Avoid the php extension on a data file - it will cause PHP to parse the file, but there is no PHP in it. The "2048" value on line 2 of the loop is set for long lines. 1024 works fine, but I had to increase it with a large database I use a similar script to read. You don't need to open and close the speech marks (as in gozer at fanhunter dot com's example) in the echo line, just use the variables inbetween the dashes. (Remove the line break halfway through the echo line - it is just there for this forum.) ---- Manual Page -- http://www.php.net/manual/en/function.fscanf.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+42648 Delete -- http://master.php.net/manage/user-notes.php?action=delete+42648&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+42648&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#70053) next »