2015-07-18 4 views
5

Ich habe ein PHP-Skript gemacht, die ein ganzes Verzeichnis mit Textdateien darin durchsucht, alles funktioniert gut, außer dass die Groß-/Kleinschreibung beachtet wird. Wie würde ich suchen, ohne dass Groß- und Kleinschreibung beachtet wird? Hier ist der Code, den ich bisher habe:Wie verwendet man PHP strpos nicht Groß-und Kleinschreibung?

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

stripos http://php.net/manual/en/function.stripos.php passend genug –

+0

möglich Duplikat: http://stackoverflow.com/questions/6795383/how-to-make-strap-case-insensitive –

+0

Ich habe diese Frage nicht einmal gesehen. –

Antwort

8

Ja, stripos() ist das, was Sie suchen. Hier ist the manual page.

+0

Vielen Dank. Das funktioniert –

Verwandte Themen