How can PHP developers efficiently replace both "\n" and "\r" characters in a string with a single function call?

To efficiently replace both "\n" and "\r" characters in a string in PHP, developers can use the str_replace() function with an array of characters to replace and their replacements. By passing an array with "\n" and "\r" as keys and an empty string as their respective values, both newline and carriage return characters can be removed in a single function call.

$string = "Hello\nWorld\r!";
$cleaned_string = str_replace(array("\n", "\r"), '', $string);
echo $cleaned_string;