cvs: pear /PHP_Compat/Compat/Function strripos.php

From: Date: Mon, 30 May 2005 20:42:09 +0000
Subject: cvs: pear /PHP_Compat/Compat/Function strripos.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-32256@lists.php.net to get a copy of this message
aidan Mon May 30 16:42:09 2005 EDT Modified files: /pear/PHP_Compat/Compat/Function strripos.php Log: Fix bug #4480 and first-last-letter scan bug http://cvs.php.net/diff.php/pear/PHP_Compat/Compat/Function/strripos.php?r1=1.21&r2=1.22&ty=u Index: pear/PHP_Compat/Compat/Function/strripos.php diff -u pear/PHP_Compat/Compat/Function/strripos.php:1.21 pear/PHP_Compat/Compat/Function/strripos.php:1.22 --- pear/PHP_Compat/Compat/Function/strripos.php:1.21 Tue Jan 25 23:55:13 2005 +++ pear/PHP_Compat/Compat/Function/strripos.php Mon May 30 16:42:08 2005 @@ -16,7 +16,7 @@ // | Stephan Schmidt <schst@php.net> | // +----------------------------------------------------------------------+ // -// $Id: strripos.php,v 1.21 2005/01/26 04:55:13 aidan Exp $ +// $Id: strripos.php,v 1.22 2005/05/30 20:42:08 aidan Exp $ /** @@ -27,7 +27,7 @@ * @link http://php.net/function.strripos * @author Aidan Lister <aidan@php.net> * @author Stephan Schmidt <schst@php.net> - * @version $Revision: 1.21 $ + * @version $Revision: 1.22 $ * @since PHP 5 * @require PHP 4.0.0 (user_error) */ @@ -55,7 +55,7 @@ // Manipulate the string if there is an offset $fix = 0; if (!is_null($offset)) { - // If the offset is larger than the haystack, return + // If the offset is larger than the haystack, return false if (abs($offset) >= strlen($haystack)) { return false; } @@ -66,12 +66,26 @@ // We need to add this to the position of the needle $fix = $offset; } else { - $haystack = substr($haystack, 0, strlen($haystack) + $offset); + // Check if the last letter of the new haystack (with offset + // taken into account) is the same as the first letter of + // the needle + if ($haystack{strlen($haystack) + $offset} === $needle{0}) { + // We need to add the length of the needle back onto the haystack + $haystack = substr($haystack, 0, strlen($haystack) + $offset + 1 + strlen($needle)); + } else { + // Only simple chop required + $haystack = substr($haystack, 0, strlen($haystack) + $offset + 1); + } } } $segments = explode(strtolower($needle), strtolower($haystack)); + // Pattern not found + if (count($segments) === 1) { + return false; + } + $last_seg = count($segments) - 1; $position = strlen($haystack) + $fix - strlen($segments[$last_seg]) - strlen($needle);

« previous php.pear.cvs (#32256) next »