note 45800 deleted from function.explode by bjori
| From: | bjori@php.net | Date: | Mon, 25 Sep 2006 08:12:29 +0000 |
| Subject: | note 45800 deleted from function.explode by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-117602@lists.php.net to get a copy of this message | ||
Note Submitter: jtgalkowski at alum dot mit dot edu
----
That explode returns FALSE when a null string is passed as the delimiting string can be unfortunate
if all that wants doing is to explode a string into an array one "character" per array
cell. This can be done using chunk_split at the cost of devoting a character to be used as an
interim delimiter. Thus,
function flatExplodeUsing( $safeCharacter, $aString ) {
$a = explode( $safeCharacter, chunk_split( $aString, 1, $safeCharacter ) ) ;
unset( $a[strlen($aString)] ) ;
return( $a ) ;
}
and
var_dump( flatExplodeUsing( "\xff", 'abcdef' ) ) ;
yields
array(6) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1)
"c" [3]=> string(1) "d"
[4]=> string(1) "e" [5]=> string(1) "f" }