note 29495 added to function.strrpos

From: Date: Sat, 15 Feb 2003 11:03:24 +0000
Subject: note 29495 added to function.strrpos
Groups: php.notes 
Request: Send a blank email to php-notes+get-43965@lists.php.net to get a copy of this message
refering to the comment and function about lastIndexOf()... It seemed not to work for me the only reason I could find was the haystack was reversed and the string wasnt therefore it returnt the length of the haystack rather than the position of the last needle... i rewrote it as fallows: function strlpos($f_haystack,$f_needle) { $rev_str = strrev($f_needle); $rev_hay = strrev($f_haystack); $hay_len = strlen($f_haystack); $ned_pos = strpos($rev_hay,$rev_str); $result = $hay_len - $ned_pos - strlen($rev_str); return $result; } this one fallows the strpos syntax rather than java's lastIndexOf. I'm not positive if it takes more resources assigning all of those variables in there but you can put it all in return if you want, i dont care if i crash my server ;). ~SILENT WIND OF DOOM WOOSH! -- http://www.php.net/manual/en/function.strrpos.php http://master.php.net/manage/user-notes.php?action=edit+29495 http://master.php.net/manage/user-notes.php?action=delete+29495 http://master.php.net/manage/user-notes.php?action=reject+29495

« previous php.notes (#43965) next »