As far as I know, the best way to split a line into new lines is preg_split and \R :
preg_split('~\R~', $str);
\R matches any Unicode Newline Sequence sequence, i.e. not only LF , CR , CRLF , but also more exotic ones like VT , FF , NEL , LS and PS .
If this behavior is not required (why?), You can specify the BSR_ANYCRLF option:
preg_split('~(*BSR_ANYCRLF)\R~', $str);
This will only match the "classic" newline sequences.
source share