php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #5446 split() is returning garbage characters
Submitted: 2000-07-07 23:14 UTC Modified: 2000-07-08 11:05 UTC
From: rasmus@php.net Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 4.0 Latest CVS (07/07/2000) OS: Linux 2.4
Private report: No CVE-ID: None
 [2000-07-07 23:14 UTC] rasmus@php.net
    $fp = fopen('slideshow.txt','r');
    while(true) {
        $line = fgets($fp,256);
        if(!feof($fp)) {
            list($file,$text) = split('[[:space:]]+',$line,2);
            echo $text."<br>\n";
        } else break;
    }

and slideshow.txt contains:

title.php       Scripting the Web
agenda.php      Agenda
intro.php       Introduction
history.php     History
numbers.php     Usage Numbers

Output:
Scripting the Web 
Agenda 
Introduction 
History a 
Usage Numbers 

Note the extra 'a' on the History line.  This character changes on every reload.  Smells like an off-by-one somewhere.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-07-08 11:05 UTC] stas at cvs dot php dot net
Fixed in CVS. The bug was actually in fgets, not split. It's just a well-masked bug.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Mon Oct 12 15:00:01 2026 UTC