Anonymous user / 3.91.19.28 Log In Register
?
Wallet: 3.00
Daily Credits:
1.20 / 1.20

PHP Functions Online


strrpos

(PHP 4, PHP 5)

strrposFind the position of the last occurrence of a substring in a string

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

Checkout ? #

Item Description Item Price Your Price
Total

Preview #

${{ variable.param.name }} = {{ variable.param|getValue:variable.form:true }};
{{ call.result}} = ;

Description #

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

Find the numeric position of the last occurrence of needle in the haystack string.

Parameters #

haystack

The string to search in.

needle

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

offset

If specified, search will start this number of characters counted from the beginning of the string. If the value is negative, search will instead start from that many characters from the end of the string, searching backwards.

Return Values #

Returns the position where the needle exists relative to the beginnning of the haystack string (independent of search direction or offset). Also note that string positions start at 0, and not 1.

Examples #

Example #1 Checking if a needle is in the haystack

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

$pos 
strrpos($mystring"b");
if (
$pos === false) { // note: three equal signs
    // not found...
}

?>

Changelog #

Version Description
5.0.0 The needle may now be a string of more than one character.
5.0.0 The offset parameter was introduced.

See Also #

  • Main PHP Function Online page
  • strpos() - Find the position of the first occurrence of a substring in a string
  • stripos() - Find the position of the first occurrence of a case-insensitive substring in a string
  • strripos() - Find the position of the last occurrence of a case-insensitive substring in a string
  • strrchr() - Find the last occurrence of a character in a string
  • substr() - Return part of a string