PHP Normalize Newlines/Line Endings; CRLF; CR; LF; UNIX, Windows, Mac
PHP
define('CR', "\r"); // Carriage Return: Mac
define('LF', "\n"); // Line Feed: Unix
define('CRLF', "\r\n"); // Carriage Return and Line Feed: Windows
define('BR', '<br />' . LF); // HTML Break
PHP
function normalize($s) {
// Normalize line endings using Global
// Convert all line-endings to UNIX format
$s = str_replace(CRLF, LF, $s);
$s = str_replace(CR, LF, $s);
// Don't allow out-of-control blank lines
$s = preg_replace("/\n{2,}/", LF . LF, $s);
return $s;
}
PHP
function normalize($s) {
// Normalize line endings
// Convert all line-endings to UNIX format
$s = str_replace("\r\n", "\n", $s);
$s = str_replace("\r", "\n", $s);
// Don't allow out-of-control blank lines
$s = preg_replace("/\n{2,}/", "\n\n", $s);
return $s;
}
Tip BCH: qrt9edpnmmr65xsnd3xdlfa0r6rpt36rfqrevu6h54
Tip BTC: 1NX28KTAVbeWai4UFqJZXYDMMpr6SwLYCw
Tip ETH: 0x53bEc9317d97a7BEBD68957A87C39EA54cD20a48
Tip LTC: LhDAkf1MLRepNe9PUuuJSPuAvx8GHqA1ed