php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34477 strtok() treats repeat of characters as single occurance
Submitted: 2005-09-12 10:16 UTC Modified: 2005-09-12 10:37 UTC
From: black at scene-si dot org Assigned:
Status: Not a bug Package: Strings related
PHP Version: 4.4.0 OS: linux deb
Private report: No CVE-ID: None
 [2005-09-12 10:16 UTC] black at scene-si dot org
Description:
------------
strtok() ignores repeats of "arg2" ie. needle, and treats it as a single occurance, skipping all repetitions

Reproduce code:
---------------
$query = "wtf ? omg ? wtf ???, ?";
$arguments = array(1,2,3,4,5,6);

var_dump($query);
$sql = strtok($query,"?");
var_dump($sql);
$retval = "";
while ($sql!==false) {
    $wasempty = empty($arguments);
    $val = array_shift($arguments);
    $retval .= $sql;
    if (!is_null($val) || !$wasempty) {
        $retval .= "'".$this->escape($val).'\'';
    }
    $sql = strtok("?");
    var_dump($sql);
}
echo $retval;


Expected result:
----------------
string(22) "wtf ? omg ? wtf ???, ?"
string(4) "wtf "
string(5) " omg "
string(5) " wtf "
string(0) ""
string(0) ""
string(2) ", "
bool(false)
wtf '1' omg '2' wtf '3''4''5', '6'


Actual result:
--------------
string(22) "wtf ? omg ? wtf ???, ?"
string(4) "wtf "
string(5) " omg "
string(5) " wtf "
string(2) ", "
bool(false)
wtf '1' omg '2' wtf '3', '4'

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-12 10:37 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is modelled after unix' strtok:
http://www.opengroup.org/onlinepubs/007908799/xsh/strtok.html
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 08:01:35 2024 UTC