How can one convert \r\n into a paragraph using PHP?

To convert \r\n into a paragraph using PHP, you can use the built-in function nl2br(). This function converts newlines (\r\n, \n) into HTML line breaks (<br>). Simply pass the string containing \r\n to nl2br() and it will replace the line breaks with <br> tags, effectively creating paragraphs.

$text_with_linebreaks = &quot;This is a line with \r\n a line break.&quot;;
$text_with_paragraphs = nl2br($text_with_linebreaks);

echo $text_with_paragraphs;