The End of Line in PHP
The end of a line in multiline text is
a special invisible character. In Windows OS
it is \r\n, while in Linux it is
simply \n.
That is, it is a different character under different
operating systems. You can work with different
variants of this character, or you can use
a special constant PHP_EOL, which
on Windows denotes \r\n, and on
Linux \n.
Since development is most often done under
Windows, and hosting is mainly on Linux -
using PHP_EOL is the most optimal
option.
Let's, for example, get an array of all lines that contain line breaks:
<?php
$str = 'text text text';
var_dump(explode(PHP_EOL, $str));
?>
Or remove all line breaks:
<?php
$str = 'text text text';
$str = str_replace(PHP_EOL, '', $str); // get text without line breaks
?>