note 93718 modified in function.preg-split by thiago
| From: | thiago@php.net | Date: | Thu, 24 Sep 2009 11:16:38 +0000 |
| Subject: | note 93718 modified in function.preg-split by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-161012@lists.php.net to get a copy of this message | ||
If you want to use something like explode(PHP_EOL, $string) but for all combinations of \r and \n,
try this one:
<?php
$text = "A\nB\rC\r\nD\r\rE\n\nF";
$texts = preg_split("/((\r(?!\n))|((?<!\r)\n)|(\r\n))/", $text);
?>
result:
array("A", "B", "C", "D", "", "E",
"", "F");
--was--
If you want to use something like explode(PHP_EOL, $string) but for all combinations of \r and \n,
try this one:
$text = "A\nB\rC\r\nD\r\rE\n\nF";
$texts = preg_split("/((\r(?!\n))|((?<!\r)\n)|(\r\n))/", $text);
result:
array("A", "B", "C", "D", "", "E",
"", "F");
http://php.net/manual/en/function.preg-split.php