What potential pitfalls should be considered when using PHP to handle form data with line breaks from a database?

When handling form data with line breaks from a database in PHP, one potential pitfall to consider is the need to properly handle line breaks to prevent any unintended formatting issues or security vulnerabilities. One solution is to use the PHP function nl2br() to convert newline characters to HTML line breaks before displaying the data on a webpage.

// Retrieve form data with line breaks from the database
$data = $row['form_data'];

// Convert newline characters to HTML line breaks
$formatted_data = nl2br($data);

// Display the formatted data on the webpage
echo $formatted_data;