Справочники, инструменты, документация

PHP: Поиск по текстовому файлу

Поиск слов в файлах txt используя PHP.
function starts_with($haystack, $needle) {
  $length = strlen($needle);
  return (substr($haystack, 0, $length) === $needle);
}

function word_printer($user_input) {
  $file = fopen("words.txt", "r");
  while (!feof($file)) {
    $word = fgets($file);
    if (starts_with($word, $user_input) == true) {
      echo "<li> $word </li>";
    }
  }
}
if (isset($_GET['q']) && !empty($_GET['q'])) {
  echo "<hr>";
  $q = $_GET['q'];
  echo "YOU SEARCHED FOR $q";
  word_printer($q);

Скачать пример