note 27750 added to function.strrpos

From: Date: Tue, 17 Dec 2002 17:47:39 +0000
Subject: note 27750 added to function.strrpos
Groups: php.notes 
Request: Send a blank email to php-notes+get-41025@lists.php.net to get a copy of this message
I was looking for the equivalent of Java's lastIndexOf(). I couldn't find it so I wrote this: /* Method to return the last occurrence of a substring within a string */ function last_index_of($sub_str,$instr) { if(strstr($instr,$sub_str)!="") { return(strlen($instr)-strpos(strrev($instr),$sub_str)); } return(-1); } It returns the numerical index of the substring you're searching for, or -1 if the substring doesn't exist within the string. -- http://www.php.net/manual/en/function.strrpos.php http://master.php.net/manage/user-notes.php?action=edit+27750 http://master.php.net/manage/user-notes.php?action=delete+27750 http://master.php.net/manage/user-notes.php?action=reject+27750

« previous php.notes (#41025) next »