+4 votes
in Programming Languages by (5.8k points)
I want to do a case-insensitive search of a substring in a string. What PHP function should I use?

1 Answer

0 votes
by (1.7k points)

You can use PHP function stripos() to find the position of the first occurrence of a substring inside a string. stripos() can be used for a case-insensitive search.

E.g.

<?php
$string1 = "Hello Everybody, where ArE you?";
$substring1 = "everybody";

if (stripos($string1, $substring1) === False)
    echo "Not Found";
else
    echo "Found<br />";
    echo stripos($string1, $substring1);
?>

...