note 98466 added to function.preg-split
| From: | smt at hotmail dot com | Date: | Thu, 17 Jun 2010 14:42:32 +0000 |
| Subject: | note 98466 added to function.preg-split | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170203@lists.php.net to get a copy of this message | ||
@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.
----
Server IP: 69.147.83.197
Probable Submitter: 38.96.167.34
----
Manual Page -- http://www.php.net/manual/en/function.preg-split.php
Edit -- https://master.php.net/note/edit/98466
Del: integrated -- https://master.php.net/note/delete/98466/integrated
Del: useless -- https://master.php.net/note/delete/98466/useless
Del: bad code -- https://master.php.net/note/delete/98466/bad+code
Del: spam -- https://master.php.net/note/delete/98466/spam
Del: non-english -- https://master.php.net/note/delete/98466/non-english
Del: in docs -- https://master.php.net/note/delete/98466/in+docs
Del: other reasons-- https://master.php.net/note/delete/98466
Reject -- https://master.php.net/note/reject/98466
Search -- https://master.php.net/manage/user-notes.php