What are some alternative approaches in PHP to handling text input formatting and line breaks to ensure consistency in display output?

When dealing with text input in PHP, it's important to ensure consistency in display output by handling formatting and line breaks properly. One approach is to use the nl2br() function to convert newline characters to HTML line breaks, ensuring that line breaks are displayed consistently across different platforms.

// Example of using nl2br() function to handle line breaks in text input
$text = "Hello\nWorld!";
$formatted_text = nl2br($text);

echo $formatted_text;