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

1 Answer

+2 votes
by (40.5k points)
selected by
 
Best answer

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


...