Quickly finding lines that match a pattern : preg_grep « String « PHP






Quickly finding lines that match a pattern

 
<?
$pattern = "/\bo'reilly\b/i"; // only O'Reilly books
$ora_books = preg_grep($pattern, file('/path/to/your/file.txt'));
?>
  
  








Related examples in the same category

1.preg_grep
2.preg_grep() function searches all elements of input_array, returning all elements matching the regexp pattern.
3.Using preg_grep()