PHP – mb_stripos() function


The mb_stripos() function in PHP is used to find the position of first occurrence of a string within another string. It is "case-insensitive". mbstripos() returns the numeric position of the first existence of the needle in a given haystack string. If the needle is not found, it will return False.

Syntax

integer mb_stripos($str_haystack, $str_needle, $int_offset=0, $str_ecoding=empty)

Parameters

It accepts the following four parameters −

  • $str_haystack − This parameter is used to get the position of the first existence of the needle from the given string.

  • $str_needle − This parameter is used to find the string from the given haystack.

  • $int_offset − This parameter is used to search the position of the string in a haystack. If the offset is negative, then it counts from the end of the given string.

  • $str_encoding − Character encoding name that is to be used. If it is omitted, then the internal character encoding is used.

Return Values

This function returns the numeric position of the first existence of the needle in a given haystack string. If the needle is not found, then it will return False.

Example 1

<?php
   mb_internal_encoding("UTF-8");

   //using string PHP Tutorials
   // offset=0
   $string=mb_stripos("PHP Tutorials","ia", 0 );

   // output will be int(9)
   var_dump($string);
?>

Output

int(9)

Updated on: 11-Oct-2021

291 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements