note 32339 added to function.strtok

From: Date: Sat, 24 May 2003 00:09:18 +0000
Subject: note 32339 added to function.strtok
Groups: php.notes 
Request: Send a blank email to php-notes+get-48929@lists.php.net to get a copy of this message
Had a website which was using way too many of the old functionality of strtok to convert to the new >PHP 4.1.0 way so I wrote this function to mimic the way strtok was done prior to 4.1.0 function strtok_old($string, $delim = null) { static $origDelim, $origString, $origPos; if (!isset($origDelim)) { $origDelim = null; } if (!isset($origString)) { $origString = null; } if (!isset($origPos)) { $origPos = null; } // continuing an already started strtok if ($string == $origDelim) { $string = $origString; $delim = $origDelim; } // else starting from scratch else { $origString = $string; $origDelim = $delim; $origPos = 0; } if ($origPos !== false && $origPos < strlen($string)) { $newPos = strpos($string, $delim, $origPos); } else { $newPos = false; } // the token wasn't found, go to end of string if ($newPos === false) { $newPos = strlen($string); } $return = substr($string, $origPos, ($newPos - $origPos)); $origPos = ++$newPos; return $return; } ---- Manual Page -- http://www.php.net/manual/en/function.strtok.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32339 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32339&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32339&report=yes

« previous php.notes (#48929) next »