Regular expression for preg_split() by new line

If you are having issues because you don't know if each newline is just \n or \r\n or \r then none of the above answers work and a regexp works. What I did was

$lines = preg_split("/(\r\n|\n|\r)/",$content);

Then you can use the accepted answer to split the spaces.


$rowsapart = preg_split("/\n/",$rowstogether);

$colspart = preg_split("/\s/",$colstogether);

There isn't any need for regular expressions:

<?php
    $data = explode("\n", $data); // preg_split('#\n#', $data); Please don't
    foreach($data as &$row) {
        $row = explode(' ', $row); // preg_split('#\s#', $row); Seriously
    }
    print_r($data);
?>

<test></test>