Home >Backend Development >PHP Tutorial >How Can I Efficiently Remove Invisible Line Breaks from a String?
Removing Line Breaks from Strings without Characters
In situations where user input contains line breaks without visible characters, standard methods like nl2br() may not suffice. To address this issue, we present a cleaner approach that preserves the original line break placement:
To remove line breaks from a string, use str_replace():
$buffer = str_replace(array("\r", "\n"), '', $buffer);
Advantages of this approach:
Understanding the Code:
The code uses str_replace() with two parameters:
The above is the detailed content of How Can I Efficiently Remove Invisible Line Breaks from a String?. For more information, please follow other related articles on the PHP Chinese website!