Regular expression for preg_split() by new line [duplicate] Regular expression for preg_split() by new line [duplicate] php php

Regular expression for preg_split() by new line [duplicate]


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.


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>


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