What are alternative approaches to removing line breaks from text input in PHP without using nl2br?

When processing text input in PHP, line breaks can sometimes interfere with the desired formatting of the output. One common approach to removing line breaks is to use the nl2br() function, which converts newline characters to HTML line breaks. However, if you want to remove line breaks altogether without converting them to HTML, you can use alternative methods such as using the str_replace() function to replace newline characters with an empty string.

// Input text with line breaks
$inputText = "This is a text\nwith line breaks.";

// Remove line breaks using str_replace
$outputText = str_replace(array("\r", "\n"), '', $inputText);

// Output text without line breaks
echo $outputText;