note 103059 deleted from function.explode by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 12:16:17 +0000 |
| Subject: | note 103059 deleted from function.explode by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197122@lists.php.net to get a copy of this message | ||
Note Submitter: lm at ms dot net
----
while explode() and implode() are counterparts, note that it does NOT work for an empty delimiter!
solution: use str_split($str) instead of explode('', $str)
example:
<?php
$str1 = 'abc';
var_dump($str1);
$str2 = implode(',' , explode(',' , $str1)); // OK (explode with non-empty
delimiter)
var_dump($str2);
$str3 = implode('' , str_split($str1)); // OK (str_split)
var_dump($str3);
$str4 = implode('' , explode('' , $str1)); // ERROR! (explode with empty
delimiter)
var_dump($str4);
?>
returns:
string 'abc' (length=3)
string 'abc' (length=3)
string 'abc' (length=3)
Warning: explode() [function.explode]: Empty delimiter.
Warning: implode() [function.implode]: Bad arguments.
null