Thursday, September 4, 2025
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
32261 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6747 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6695 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS