Are there best practices for handling line breaks and formatting when displaying text with links in PHP?

When displaying text with links in PHP, it's important to handle line breaks and formatting properly to ensure readability and maintain a clean layout. One common approach is to use the PHP nl2br() function to convert newline characters into <br> tags, allowing the text to be displayed with appropriate line breaks while preserving the link structure.

&lt;?php
$text = &quot;This is a sample text with a link: &lt;a href=&#039;https://www.example.com&#039;&gt;Click here&lt;/a&gt;\nThis is another line of text.&quot;;
$formatted_text = nl2br($text);
echo $formatted_text;
?&gt;