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);
?>
Related Questions
- What best practices should be followed when structuring PHP code to ensure that headers are not sent prematurely, and how can developers avoid common pitfalls such as whitespace or encoding issues that may trigger errors like "Cannot send session cache limiter"?
- Ist die Verwendung von "if" zur Überprüfung von Login-Daten in PHP sicher?
- What are the limitations of using PHP to show a message during page loading compared to other technologies like JavaScript?