Search code examples
phpcase-sensitivestrpos

How to use PHP strpos not case sensitive?


I have made a php script that searches a whole directory with text files in it, everything works fine, except that it is case sensitive. How would i search without it being case sensitive? Here's the code i have so far:

<?php
    $query = $_POST['search'];
    if ($handle = opendir('posts')) {
        while (false !== ($entry = readdir($handle))) {
            if ($entry != "." && $entry != "..") {

                echo "<p>$entry ";
                $file = file_get_contents('posts/'.$entry, FILE_USE_INCLUDE_PATH);
                $check_str = strpos($file,$query);

                if ($check_str == 0) {
                    print "not found</p>";
                } else {
                    print "found</p>";
                }

            }
        }
        closedir($handle);
    }
?>

Solution

  • Yeah, stripos() is what you're looking for. Here's the manual page.