note 93718 deleted from function.preg-split by cmb
| From: | cmb@php.net | Date: | Wed, 13 May 2020 15:01:57 +0000 |
| Subject: | note 93718 deleted from function.preg-split by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-214623@lists.php.net to get a copy of this message | ||
Note Submitter: Peter -the pete- de Pijd
----
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");