How can the Multiline Modifier in PHP be used to handle errors with line breaks in textareas?

When handling errors with line breaks in textareas in PHP, the Multiline Modifier can be used to ensure that the error message is displayed correctly with line breaks preserved. By using the Multiline Modifier (/m) in regular expressions, it allows the caret (^) and dollar sign ($) metacharacters to match the start and end of each line within the textarea input.

$error_message = "This is a multiline error message\nwith line breaks";
$error_message = preg_replace('/^/m', '<br>', $error_message);
echo $error_message;