|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13995 continuation of bug #13866: strtok() misparses empty fields
Submitted: 2001-11-08 20:29 UTC Modified: 2001-11-09 02:12 UTC
From: rcpj at panix dot com Assigned:
Status: Closed Package: Strings related
PHP Version: 4.0.6 OS: OpenBSD 2.9-stable
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: rcpj at panix dot com
New email:
PHP Version: OS:


 [2001-11-08 20:29 UTC] rcpj at panix dot com
If a string contains two delimiters side by side (i.e. an empty field), strtok() treats the double delimiter as a single one and the results are shifted into the wrong variable. The previous version of the bug kept the second delimiter in the value returned by the function. This version does not, but it returns the wrong substring.

PHP version is 4.2.0-dev

(how do I report the correct version on the report form? Shouldn't there be at least a "other"?)

Example of the bug:
$String= "field1|field2||field4";

$Item1=strtok($String,"|");    // $Item1: field1
$Item2=strtok("|");               // $Item2: field2
$Item3=strtok("|");                // $Item3: field4
$Item4=strtok("|");                // $Item4 is empty

compare the outputs of:    (correct)
and    (incorrect)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-11-09 02:12 UTC]
This is the expected behavior. It conforms to alteast the C-libraries on Linux, Win32 and Solaris.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Dec 04 03:01:27 2023 UTC