Open In App

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:

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   
$str = "Hello world!";
$pos = iconv_strpos($str, 'world');
echo $pos;
?>

Output:

6

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




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

Article Tags :