Thursday, September 4, 2025
HomeLanguagesPHP iconv_strrpos() Function

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:

  • $haystack: This parameter is where we search for the last occurrence of a string.
  • $needle: This parameter defines searching a sub-string in the $haystack parameter.
  • $encoding: The character set to use. The default value is the internal encoding that will be used.

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




<?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




<?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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32262 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11857 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6696 POSTS0 COMMENTS
Umr Jansen
6716 POSTS0 COMMENTS