define('NL_NIX', "\n");
define('NL_WIN', "\r\n");
define('NL_MAC', "\r");
function newline_type($string)
{
if (strpos($string, NL_WIN) !== false) {
return NL_WIN;
} elseif(strpos($string, NL_MAC) !== false) {
return NL_MAC;
} elseif(strpos($string, NL_NIX) !== false) {
return NL_NIX;
}
}
Checks which row of a row is in a row. 0 is returned when a new line is not found.
To normalize / standardize all newlines, use the following function:
function newline_convert($string, $newline)
{
return str_replace(array(NL_WIN, NL_MAC, NL_NIX), $newline, $string);
}
Hope this helps!
source
share