What are the potential issues that may arise when trying to replace multiple occurrences of line breaks in a string using preg_replace in PHP?

When trying to replace multiple occurrences of line breaks in a string using preg_replace in PHP, one potential issue that may arise is that the pattern used to match line breaks may not work as expected. To ensure that all line breaks are properly replaced, it is important to use the correct pattern that captures all possible line break characters (\r, \n, or \r\n).

// Example code snippet to replace multiple occurrences of line breaks in a string
$string = "Hello\n\nWorld\r\r\n!";
$pattern = "/(\r\n|\r|\n)+/";
$replacement = "<br>";
$new_string = preg_replace($pattern, $replacement, $string);

echo $new_string;