How can regular expressions be used to efficiently remove line breaks from a string in PHP?

To efficiently remove line breaks from a string in PHP, regular expressions can be used to match and replace all occurrences of line breaks with an empty string. This can be done using the preg_replace() function in PHP, where the regular expression pattern "\r?\n" can be used to match both Windows-style (\r\n) and Unix-style (\n) line breaks.

$string = "This is a string with line breaks.\nLet's remove them.";
$cleaned_string = preg_replace("/\r?\n/", "", $string);

echo $cleaned_string;