How can PHP automatically delete file content after rea…
In PHP, you can use the file_get_contents() function to read the contents of a file, and then use the unlink() function to delete the file.
Here is an example code:
$file = 'example.txt';
// 读取文件内容
$content = file_get_contents($file);
// 打印文件内容
echo $content;
// 删除文件
unlink($file);
echo '文件已删除';
In the code above, content of a file is first read using the file_get_contents() function and saved in the variable $content. Then the file is deleted using the unlink() function. Finally, the content of the file is printed and a message is displayed.
Please make sure that the file is no longer needed and has appropriate permissions before using the unlink() function to delete it.