First line break:
$match = preg_split('/\R/', $str, 2);
First blank line:
$match = preg_split('/\R\R/', $str, 2);
Handles all the different ways to perform line breaks.
There was also the question of splitting the second line at break. Here is my implementation (maybe not the most efficient ... also note that it replaces some line breaks with PHP_EOL )
function split_at_nth_line_break($str, $n = 1) { $match = preg_split('/\R/', $str, $n+1); if (count($match) === $n+1) { $rest = array_pop($match); } $match = array(implode(PHP_EOL, $match)); if (isset($rest)) { $match[] = $rest; } return $match; } $match = split_at_nth_line_break($str, 2);
source share