Wednesday, January 21, 2026
HomeLanguagesPHP iconv_strpos() Function

PHP iconv_strpos() Function

The iconv_strpos() is an inbuilt function in PHP that is used for finding a position in the substring and returning that position.

Syntax:

iconv_strpos( 
    string $haystack, 
    string $needle, 
    int $offset = 0, 
    ?string $encoding = null ): int|false

Parameters: The function takes 4 parameters that are described below:

  • $haystack: This parameter species the complete string.
  • $needle: This parameter specifies the substring to search for.
  • $offset: The position in $haystack to start searching from. It will evaluate from the end of the string if the value of offset is found to be negative.
  • $encoding: This parameter specifies the character set to use. The default value is the internal encoding set used. It transforms & provides the string & implements it as the ordinal value of a character if the haystack or needle is not found in a string.

Return Values: The iconv_strpos() returns the first occurrence of $needle in $haystack otherwise it will return “false” if the $needle is not found in $haystack.

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

PHP




<?php   
$str = "Hello world!";
$pos = iconv_strpos($str, 'world');
echo $pos;
?>


Output:

6

Example 2: The following program demonstrates the iconv_strpos() function

PHP




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


Output:

12

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

RELATED ARTICLES

Most Popular

Dominic
32475 POSTS0 COMMENTS
Milvus
119 POSTS0 COMMENTS
Nango Kala
6847 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12064 POSTS0 COMMENTS
Shaida Kate Naidoo
6986 POSTS0 COMMENTS
Ted Musemwa
7220 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6912 POSTS0 COMMENTS