What are best practices for handling line breaks and special characters in PHP when converting text to XHTML?
When converting text to XHTML in PHP, it's important to properly handle line breaks and special characters to ensure the content displays correctly in the browser. To do this, you can use the PHP functions nl2br() to convert line breaks to <br> tags and htmlspecialchars() to encode special characters.
$text = "This is a text with line breaks\nand special characters like < and >";
$text = nl2br(htmlspecialchars($text));
echo $text;