PHP

HOW TO REMOVE LINE BREAKS IN PHP

(simple examples)

$str = "Hello  World  Foo Bar!";   $nobreak = str_replace(["\r", "\n"], "", $str);

STRING REPLACE

01

$str = "Hello World Foo Bar!";   $nobreak = preg_replace("/\r|\n/", "", $str);

REGULAR EXPRESSION

02

$str = "  Hello World  ";   ONLY REMOVES LEADING & TRAILING LINE BREAKS $nobreak = trim($str);

STRING TRIM

03

$str = "Hello<br>World";   $nobreak = str_replace(["<br>", "<br/>"], "", $str);

HTML BREAKS

04