note 91529 added to function.explode
| From: | marcus at synchromedia dot co dot uk | Date: | Mon, 15 Jun 2009 13:50:37 +0000 |
| Subject: | note 91529 added to function.explode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-156896@lists.php.net to get a copy of this message | ||
Just in case the comment about empty strings is not clear:
<?php
$a = array();
var_dump($a);
$s = implode("\n", $a);
var_dump($s);
$b = explode("\n", $s);
var_dump($b);
$b = preg_split('/\n/', $s,-1,PREG_SPLIT_NO_EMPTY);
var_dump($b);
?>
Results in:
array(0) {
}
string(0) ""
array(1) {
[0]=>
string(0) ""
}
array(0) {
}
i.e. exploding an empty string results in an array with one element. You can use preg_split to skip
the empty item, but that may not be quite what you need should your array have empty elements
intentionally.
----
Server IP: 92.48.74.199
Probable Submitter: 87.74.30.27
----
Manual Page -- http://www.php.net/manual/en/function.explode.php
Edit -- https://master.php.net/note/edit/91529
Del: integrated -- https://master.php.net/note/delete/91529/integrated
Del: useless -- https://master.php.net/note/delete/91529/useless
Del: bad code -- https://master.php.net/note/delete/91529/bad+code
Del: spam -- https://master.php.net/note/delete/91529/spam
Del: non-english -- https://master.php.net/note/delete/91529/non-english
Del: in docs -- https://master.php.net/note/delete/91529/in+docs
Del: other reasons-- https://master.php.net/note/delete/91529
Reject -- https://master.php.net/note/reject/91529
Search -- https://master.php.net/manage/user-notes.php