Open In App

PHP iconv_strrpos() Function

The iconv_strrpos() function is an inbuilt function in PHP that searches for the last occurrence of a substring within a string while taking the character encoding of the string into account. It is similar to the strrpos() function, but it supports multi-byte character sets.

Syntax:



int|false iconv_strrpos(
    string $haystack, 
    string $needle, 
    ?string $encoding = null
)

Parameters: The function accepts three parameters that are described below:

Return Values: The numeric position of the last occurrence of the substring within the string, or “false” if the substring is not found in the string. 



Example 1: The following program demonstrates the iconv_strrpos() function.




<?php
$str = "Hello world, hello universe!";
$pos = iconv_strrpos($str, "hello");
echo $pos;
?>

Output:

13

Example 2: The following program demonstrates the iconv_strrpos() function.




<?php
$str = "München ist schön. München ist groß.";
$pos = iconv_strrpos($str, "München", "UTF-8");
echo $pos;
?>

Output:

19

Reference: https://www.php.net/manual/en/function.iconv-strrpos.php

Article Tags :