The stripos Function

The stripos function finds the first occurrence of a substring in a string, ignoring case. Its first parameter is the string to search in, the second is the substring to search for, and the third optional parameter is the position to start the search from.

Syntax

phpstripos(string, substring, [offset]);

Example

Find the position of a substring in a string:

php<?php
  echo stripos('AbCdE', 'bc');
?>

Code execution result:

php1

Example

Try to find a non-existent substring:

php<?php
  $res = stripos('AbCdE', 'xyz');
  var_dump($res);
?>

Code execution result:

phpfalse

Example

Search with a specified starting position:

php<?php
  echo stripos('aAbBcC', 'b', 3);
?>

Code execution result:

php4

See Also

  • the strpos function,
    which performs a case-sensitive search
  • the stristr function,
    which returns the part of the string after the found occurrence