# PHP – mb_strrpos() function

PHPServer Side ProgrammingProgramming

The mb_strrpos() function in PHP is used to find the position of the last occurrence of a string in another string. This function performs the multibyte safe strrpos() operation based on the number of characters. It counts the needle position from the starting of the haystack string.

## Syntax

int mb_strrpos(
$str_haystack,$str_needle,
$int_offset=0,$str_encoding=empty
)

## Parameters

mb_strrpos() accepts the following four parameters −

• $str_haystack − This parameter is used to check the string for the last existence of the needle string. •$str_needle − This needle parameter is used to find the string in the given haystack.

• $int_offset − This parameter is used to search the arbitrary number of characters in the string. If the value is negative, then the offset will stop searching the string at an arbitrary point to the end of the given string. •$str_encoding − This is the character encoding parameter. If the encoding is omitted, then we can use the internal character encoding value.

## Return Values

mb_strrpos() returns the numeric position of the last occurrence of the needle in the given haystack string. If the needle is not found, then it returns False.

## Example 1

<?php
// Encoding UTF-8
mb_internal_encoding("UTF-8");

// Used hello world string
$integer = mb_strrpos ("Hello World", "ol", 0); //Output var_dump($integer);
?>

## Output

bool(false)


Note − The above PHP code returns False because the needle string is not matched with the given haystack string.

## Example 2

<?php
// Encoding UTF-8
mb_internal_encoding("UTF-8");

// Used hello world string
$integer = mb_strrpos ("Hello World", "He"); //output var_dump($integer);
?>

## Output

int(0)

Published on 11-Oct-2021 13:44:01