note 98466 deleted from function.preg-split by danbrown

From: Date: Thu, 17 Jun 2010 14:48:24 +0000
Subject: note 98466 deleted from function.preg-split by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-170204@lists.php.net to get a copy of this message
Note Submitter: smt at hotmail dot com ---- @Peter de Pijd: "If you want to use something like explode(PHP_EOL, $string) but for all combinations of \r and \n, try this one" There is a much easier way to split text by line breaks: <?php $text = "A\n\r\n\nB\nC\rD\n\n\rE\r\r\nF\n\rG\r"; // '@' is an easier-to-read delimiter than '/' $letters = preg_split('@[\n\r]+@', $text); ?> The regex [\n\r]+ will match any combination of consecutive \r and \n characters of any length.

« previous php.notes (#170204) next »