What is the recommended method for storing guestbook entries in a text file using PHP?

When storing guestbook entries in a text file using PHP, it is recommended to use a delimiter to separate each entry. This makes it easier to read and parse the file later on. Additionally, it is important to properly sanitize and validate user input to prevent any security vulnerabilities.

// Code snippet to store guestbook entries in a text file using PHP

// Sanitize and validate user input
$name = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$message = filter_var($_POST['message'], FILTER_SANITIZE_STRING);

// Create a formatted entry with a delimiter
$entry = $name . "|" . $message . PHP_EOL;

// Append the entry to the text file
file_put_contents('guestbook.txt', $entry, FILE_APPEND);