note 35619 added to function.strcmp
| From: | gregd at sad dot net | Date: | Mon, 08 Sep 2003 15:49:17 +0000 |
| Subject: | note 35619 added to function.strcmp | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-55854@lists.php.net to get a copy of this message | ||
In cases when you need to compare a line from a just parsed file stream to match a user-defined
"nametag" (useful for parsing ini and configuration files), keep in mind the 'end of
line' tags as well:
// nametag to look for in a file (notice a required "\r\n" at the end)
$nametag = "[System]\r\n";
// ...assuming the file has been aready opened for reading and the stream is bound to $filehandle...
parse the file until an EOF or $nametag encountered.
while (!feof ($handle))
{
$buffer = fgets($filehandle);
if (strcmp($nametag, $buffer) == 0)
{
// at this point "[System]" is found, do additional parsings...
break;
}
}
----
Manual Page -- http://www.php.net/manual/en/function.strcmp.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35619
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35619&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35619&report=yes