How can automatic line breaks in a guestbook entry be handled to prevent page layout issues in PHP?

When handling automatic line breaks in a guestbook entry in PHP, it's important to convert the line breaks to HTML line breaks (<br>) to ensure proper formatting on the page. This can be achieved using the nl2br() function in PHP, which converts newlines to HTML line breaks.

// Assuming $guestbookEntry contains the text input from the guestbook
$guestbookEntry = nl2br($guestbookEntry);

// Display the guestbook entry with HTML line breaks
echo $guestbookEntry;