note 18720 added to function.strrpos

From: Date: Fri, 01 Feb 2002 21:06:41 +0000
Subject: note 18720 added to function.strrpos
Groups: php.notes 
Request: Send a blank email to php-notes+get-26141@lists.php.net to get a copy of this message
To find the position of the start of the last occurence of a string, we can do this: $pos=strlen($haystack) - (strpos(strrev($haystack), strrev($needle)) + strlen($needle)); The idea is to reverse both $needle and $haystack, use strpos to find the first occurence of $needle in $haystack, then count backwards by the length of $needle. Finally, subtract $pos from length of $haystack. A lot easier to figure out if you use a test string to visualize it. :) -- http://www.php.net/manual/en/function.strrpos.php http://master.php.net/manage/user-notes.php?action=edit+18720 http://master.php.net/manage/user-notes.php?action=delete+18720 http://master.php.net/manage/user-notes.php?action=reject+18720

« previous php.notes (#26141) next »