How can PHP be used to properly format and display HTML content, such as converting new lines to <br> tags?
To properly format and display HTML content in PHP, we can use the nl2br() function to convert new lines in the text to <br> tags. This function replaces all new line characters (\n) with the <br> tag, allowing the text to be displayed with line breaks in HTML.
<?php
$text = "This is a sample text with\nnew lines.";
$formatted_text = nl2br($text);
echo $formatted_text;
?>