What best practices should be followed when passing multi-line text from an HTML form to imagettftext in PHP?

When passing multi-line text from an HTML form to imagettftext in PHP, it is important to properly handle line breaks and ensure that the text is formatted correctly for the imagettftext function to display it correctly on an image. One way to achieve this is by using the PHP function nl2br() to convert newline characters to HTML line breaks before passing the text to imagettftext.

// Get the multi-line text from the HTML form
$multiLineText = $_POST['multi_line_text'];

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

// Pass the formatted text to imagettftext
imagettftext($image, $font_size, $angle, $x, $y, $text_color, $font_file, $multiLineText);