Re: note 8942 added to explode

From: Date: Sat, 07 Oct 2000 18:04:09 +0000
Subject: Re: note 8942 added to explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-6205@lists.php.net to get a copy of this message
You have the parameters in the wrong order, see the manual entries carefully for the function definition. The separator should be the first parameter, not the string to be parsed. Implode() is very lenient with parameter ordering, but explode() has no way of simply determining which parameter would be the separator and which one the string to be exploded (at least not in a a general way). The code below: <?php $a = array(2,4,6,8); $b = implode("|",$a); $c = explode("|",$b); print_r($a); echo $b."\n"; print_r($c); ?> Prints: Array ( [0] => 2 [1] => 4 [2] => 6 [3] => 8 ) 2|4|6|8 Array ( [0] => 2 [1] => 4 [2] => 6 [3] => 8 ) Your note will be removed. --- v@w.cl wrote: > Implode and explode can behave differently. > > I can write > > $a=implode($array,"|"); > > and $a would be the expected string separated by |. > > But if I write > > $array=explode($a,"|"); > > $array would NOT be the original $array, but an > empty value. > > And neither implode or explode throws a warning > about the bad parameter passing. > > http://www.php.net/manual/function.explode.php > > > -- > PHP Notes Mailing List (http://www.php.net/) > To unsubscribe, e-mail: > php-notes-unsubscribe@lists.php.net > For additional commands, e-mail: > php-notes-help@lists.php.net > To contact the list administrators, e-mail: > php-list-admin@lists.php.net > ===== --- Jesus M. Castagnetto (jcastagnetto@yahoo.com) __________________________________________________ Do You Yahoo!? Yahoo! Photos - 35mm Quality Prints, Now Get 15 Free! http://photos.yahoo.com/

« previous php.notes (#6205) next »