PHP
Advertisement

Finds the last occurrence of a string inside a string.

Arguments[]

void strrpos ({{{params}}})


Argument Inclusion[]

  • strrpos needs PHP version 4 or 5 to work.

Return values[]

strrpos will return the numeric position of the last search string inside the given string. Note that the position in string starts with 0 and not with 1. If the optional offset parameter was set it starts searching at the character with that number. The return value will still be relative to the beginning of the string.

Examples[]

Example 1: The direct way[]

<?php
 echo strrpos("Find a string inside a string", "string");
?>

Output[]

23

Example 2: Using a variable and offset[]

<?php
 $string = "abc abc abc";
 $find   = "a";
 echo strrpos($string, $find, 1); // Stars searching at the first b
?>

Output[]

8
For more details on this function, visit its entry in the php manual.
Advertisement