Search code examples
phpfileawkline

How to delete a line from the file with php?


I have a file named $dir and a string named $line, I know that this string is a complete line of that file but I don't know its line number and I want to remove it from file, what should I do?

Is it possible to use awk?


Solution

  • $contents = file_get_contents($dir);
    $contents = str_replace($line, '', $contents);
    file_put_contents($dir, $contents);