0

I'm using the following function to search for words in a text file. The problem is that this function is case-sensitive. I don't want it to be case-sensitive! How can I make the function case-insensitive?

$url = 'files/file.txt';
$thedata = file_get_contents($url);
$lines = explode(PHP_EOL, $thedata);

$search = 'some search words';
$pattern = preg_quote($search, '/');
$pattern = "/^.*$pattern.*\$/m";

if(preg_match_all($pattern, $thedata, $matches)) {
    echo implode('<br>', $matches[0]);    
} else {
    echo '<div class="message color-red">';
        echo 'Didn\'t find anything on that search!';
    echo '</div>';
}
Airikr
  • 6,258
  • 15
  • 59
  • 110

1 Answers1

2

Add i in addition to the m after the last / in your pattern string:

$pattern = "/^.*$pattern.*\$/mi"
Mark Reed
  • 91,912
  • 16
  • 138
  • 175