note 28212 deleted from function.fgets by sniper
| From: | sniper@php.net | Date: | Sat, 03 Jan 2004 02:46:24 +0000 |
| Subject: | note 28212 deleted from function.fgets by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-62829@lists.php.net to get a copy of this message | ||
Note Submitter: chip@vonburg.com
----
You guys are more than correct about fgets() returning the carriage return also. I ran into the same
problem and it was very frustrating to say the least. There were some great solutions here on how to
work around this, but they just seemed to be to much code for me. I was able to handle it very
easily using trim. Trim will remove all white space including carriage returns. Here is an example
of how I am doing this.
if($fp=fopen($file, "r+"))
{
while($line=trim(fgets($fp)))
{
if(!strcasecmp($line, $myline))
{
print We have a line match;
}
}
}
Hope this helps