What is the function nl2br used for in PHP and how does it handle line breaks within a CSV file?

The nl2br function in PHP is used to insert HTML line breaks (<br>) before all newlines in a string. When handling line breaks within a CSV file, nl2br can be useful for displaying the content of the file in a web page while preserving the line breaks present in the original CSV data.

&lt;?php
$csvData = &quot;Name,Age,Location\nJohn,25,New York\nJane,30,Los Angeles&quot;;
$csvDataWithLineBreaks = nl2br($csvData);

echo $csvDataWithLineBreaks;
?&gt;