I have a file that has multiple lines using tabs, newlines, and whitespaces. In PHP, I'm trying to loop through a file searching for a specific array of keywords.
Here's the array:
array('test', 'test2', 'test3')
File contents:
@test
@test3
@test2
The code:
$file = file_get_contents('file.txt');
foreach ($array as $k) {
preg_match('/(@'.$k.')$/m', $file, $m);
}
print_r($m);
The problem is it successfully matches the last element of $array (test3) regardless of any whitespaces before it. Any help would be appreciated, thanks.