note 53618 deleted from function.strpos by sean
| From: | sean@php.net | Date: | Wed, 15 Jun 2005 15:02:50 +0000 |
| Subject: | note 53618 deleted from function.strpos by sean | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-90469@lists.php.net to get a copy of this message | ||
Note Submitter: nicolas AT smileandsoft DOT com DOT ar
----
Last position of needle in haystack:
<?
function istrpos($needle, $haystack, $offset=0)
{
return (int) strlen( $haystack ) - strpos ( strrev ( $haystack ) , $needle ) + $offset;
}
$phrase = "jose//pepe/micasa/pepepe";
echo istrpos( "/" , $phrase ); //returns last position of "/" in $phrase
result:18
echo istrpos( "/" , $phrase , -1 ); //returns last position of "/" in $phrase
MINUS 1 result:17
echo substr( $phrase, istrpos( "/" , $phrase ) ); //returns "pepepe"
echo substr( $phrase, istrpos( "/" , $phrase , -1 ) ); //returns "/pepepe"
?>