5

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);
    }
?>
Jacoby Yarrow
  • 155
  • 1
  • 13

2 Answers2

9

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

Will
  • 24,082
  • 14
  • 97
  • 108
blasko
  • 690
  • 4
  • 8
0

You are maybe looking for strtolower , :

MihirUj
  • 43
  • 1
  • 11