How can a specific email address be deleted from a text file in PHP without manual intervention?

To delete a specific email address from a text file in PHP without manual intervention, you can read the contents of the file, search for the email address to be deleted, remove it from the content, and then overwrite the file with the updated content.

<?php
$filePath = 'emails.txt';
$emailToDelete = 'example@example.com';

// Read the contents of the file
$fileContent = file_get_contents($filePath);

// Remove the email address from the content
$fileContent = str_replace($emailToDelete, '', $fileContent);

// Write the updated content back to the file
file_put_contents($filePath, $fileContent);
?>