php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20877 fgets return 1 char less
Submitted: 2002-12-07 09:33 UTC Modified: 2002-12-07 15:03 UTC
From: php at 5en1 dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 4.3.0RC2 OS: red hat 7.2
Private report: No CVE-ID: None
 [2002-12-07 09:33 UTC] php at 5en1 dot com
Hi
when i do a $file=fopen("http://url","r");
$line=fgets($file,2);
$line contain only the first char of the file, not 2
this bug wasn't in the php 4.1.1 i have on another server, under which my script work without any problem.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-12-07 15:03 UTC] iliaa@php.net
This was actually a bug in the older versions of PHP that has been fixed. If you look at the fgets() documentation you will note that it specifically says:
"Returns a string of up to length - 1 bytes read from the file pointed to by fp. Reading ends when length - 1 bytes have been read, on a newline (which is included in the return value), or on EOF (whichever comes first)."
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Dec 26 06:00:01 2025 UTC