note 39220 added to function.fscanf
| From: | mattatmattsinclairdotcom at rn2 dot php dot net | Date: | Wed, 21 Jan 2004 05:36:10 +0000 |
| Subject: | note 39220 added to function.fscanf | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-63917@lists.php.net to get a copy of this message | ||
A better way to use fscanf() would be this:
<?php
$handle = fopen("users.txt", "r");
while (!feof($handle)) {
$userinfo = fscanf($handle, "%s\t%s\t%s\n");
if ($userinfo) {
list ($name, $profession, $countrycode) = $userinfo;
//... do something with the values
}
$userinfo=NULL;
}
fclose($handle);
?>
as you can see, instead of waiting for fscanf() to fail to return a value... it waits for the the
pointer to get to the end of the file... this way, if for some reason one of your lines does not
match your expression, it will not kill the loop. it will simply go on to the next line.
----
Manual Page -- http://www.php.net/manual/en/function.fscanf.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39220
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39220&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39220&report=yes
Search -- http://master.php.net/manage/user-notes.php