function longWordsRemover($filePath, $count)
{
    $text = file_get_contents($filePath);
    if ($longWordsArr = longWords($text, $count)) {
        $words = explode(' ', $text);
        $updatedArr = array_diff($words, $longWordsArr);
        $textUpdated = implode(' ', $updatedArr);
        $resource = fopen($filePath, 'w');
        flock($resource, LOCK_EX);
        if (fwrite($resource, $textUpdated) != false) {
            $status = true;
        } else {
            $status = false;
        }
        flock($resource, LOCK_UN);
        fclose($resource);
    }
    return !isset($status) ? false : $status;
    // return $status ?? false;
}
<body>
<h1> Выводим слова </h1>
<h3>Найдем 3 самых длинных слова.</h3>
<form action="<?php 
echo $_SERVER['PHP_SELF'];
?>
" method="GET">
    <textarea name="text" id="" cols="30" rows="10">Петя Леня космос Виктор Федор Сумкин Илья Viktoriya Вика john вася</textarea><br>
    </label>
    <input type="submit" value="Вывести">
    <p>
        <?php 
if (sizeof($_GET) !== false) {
    if (isset($_GET['text'])) {
        $text = trim(strip_tags($_GET['text']));
        if (sizeof($longWordsArr = longWords($text, $count)) != false) {
            echo "Самые ТОП" . $count . " длинных слов: ";
            foreach ($longWordsArr as $word) {
                echo $word . ' ';
            }
        } else {
            echo 'Ошибка обработки слов';
        }
    }
}
?>
    </p>
</form>
</body>
</html>