<?php
$file = 'files/output.txt';
$searchfor = $_POST['word'];
$contents = file_get_contents($file);
$pattern = preg_quote($searchfor, '/');
$pattern = "/^.*$pattern.*\$/m";
if ($_POST['word'] != null) {
if(preg_match_all($pattern, $contents, $matches)) {
echo "Найдено:\n";
echo implode("\n", $matches[0]);
} else {
echo "Нет совпадений";
}
} else {
echo "";
}
?>