note 75358 added to function.explode

From: Date: Fri, 25 May 2007 09:01:14 +0000
Subject: note 75358 added to function.explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-126890@lists.php.net to get a copy of this message
Watch out for this gottcha. Consider: $arr = explode("/", ""); This should return a null array (ie count($arr) == 0). Array ( ) However, explode will instead return an array of one item which is a null string. Array ( [0] => ) There is some logic to the way this works but consider the following: $addressees = "email@domain1.com, email@domain2.com"; $arr = explode(",", $addressees); foreach($arr AS $to) mail ($to, $subject, $message); with two items in the list it would sent two separate emails, with one it would sent one email message but with $addressees = "" it will still attempt to send one message that will fail because instead of returning an empty array explode returns an array with an empty item. ---- Server IP: 87.124.64.96 Probable Submitter: 62.30.219.119 ---- Manual Page -- http://www.php.net/manual/en/function.explode.php Edit -- https://master.php.net/note/edit/75358 Del: integrated -- https://master.php.net/note/delete/75358/integrated Del: useless -- https://master.php.net/note/delete/75358/useless Del: bad code -- https://master.php.net/note/delete/75358/bad+code Del: spam -- https://master.php.net/note/delete/75358/spam Del: non-english -- https://master.php.net/note/delete/75358/non-english Del: in docs -- https://master.php.net/note/delete/75358/in+docs Del: other reasons-- https://master.php.net/note/delete/75358 Reject -- https://master.php.net/note/reject/75358 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#126890) next »