note 45800 added to function.explode
| From: | jtgalkowski at alum dot mit dot edu | Date: | Sun, 19 Sep 2004 18:22:12 +0000 |
| Subject: | note 45800 added to function.explode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-76982@lists.php.net to get a copy of this message | ||
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" }
----
Manual Page -- http://www.php.net/manual/en/function.explode.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45800
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45800&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45800&report=yes
Search -- http://master.php.net/manage/user-notes.php