downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  

<strriposstrspn>
Last updated: Thu, 26 Jun 2008

strrpos

(PHP 4, PHP 5)

strrpos — Find position of last occurrence of a char in a string

Description

int strrpos ( string $haystack , string $needle [, int $offset ] )

Returns the numeric position of the last occurrence of needle in the haystack string. Note that the needle in this case can only be a single character in PHP 4. If a string is passed as the needle, then only the first character of that string will be used.

If needle is not found, returns FALSE.

It is easy to mistake the return values for "character found at position 0" and "character not found". Here's how to detect the difference:

<?php

// in PHP 4.0.0 and newer:
$pos = strrpos($mystring, "b");
if (
$pos === false) { // note: three equal signs
   // not found...
}

// in versions older than 4.0.0:
$pos = strrpos($mystring, "b");
if (
is_bool($pos) && !$pos) {
  
// not found...
}
?>

If needle is not a string, it is converted to an integer and applied as the ordinal value of a character.

Note: As of PHP 5.0.0 offset may be specified to begin searching an arbitrary number of characters into the string. Negative values will stop searching at an arbitrary point prior to the end of the string.

Note: The needle may be a string of more than one character as of PHP 5.0.0.

Parameters

haystack

needle

offset

Return Values



add a noteadd a note User Contributed Notes
Find position of last occurrence of a char in a string
There are no user contributed notes for this page.




<strriposstrspn>
Last updated: Thu, 26 Jun 2008
show source | credits | sitemap | contact | advertising | mirror sites
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: http://phpbuilder.com/
Last updated: Tue Nov 1 20:20:59 2005 EST
Columns / Articles | Tips / Quickies | News | News Linking and RSS Feeds | Shared Code Library
Mail Archives | Support / Discussion Forums | Get Started! Links | Contribute! | Docs