Home >Backend Development >PHP Tutorial >How Can I Delete a Specific Line from a File Using PHP?
Eliminating Lines from Files Using PHP
To erase a complete line from a file in PHP, where the line number is unknown, consider the following steps:
Example Code:
$contents = file_get_contents($dir); $contents = str_replace($line, '', $contents); file_put_contents($dir, $contents);
This solution effectively removes the specified line from the file without necessitating the knowledge of its line number.
The above is the detailed content of How Can I Delete a Specific Line from a File Using PHP?. For more information, please follow other related articles on the PHP Chinese website!