note 54769 added to function.fscanf
| From: | worldwideroach at hotmail dot com | Date: | Thu, 14 Jul 2005 16:33:15 +0000 |
| Subject: | note 54769 added to function.fscanf | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-91974@lists.php.net to get a copy of this message | ||
Yet another function to read a file and return a record/string by a delimiter. It is very much like
fgets() with the delimiter being an additional parameter. Works great across multiple lines.
function fgetd(&$rFile, $sDelim, $iBuffer=1024) {
$sRecord = '';
while(!feof($rFile)) {
$iPos = strpos($sRecord, $sDelim);
if ($iPos === false) {
$sRecord .= fread($rFile, $iBuffer);
} else {
fseek($rFile, 0-strlen($sRecord)+$iPos+strlen($sDelim), SEEK_CUR);
return substr($sRecord, 0, $iPos);
}
}
return false;
}
----
Manual Page -- http://www.php.net/manual/en/function.fscanf.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54769
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54769&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54769&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54769&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54769&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54769&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54769&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54769&report=yes
Search -- http://master.php.net/manage/user-notes.php