note 99841 added to function.explode

From: Date: Fri, 10 Sep 2010 00:35:15 +0000
Subject: note 99841 added to function.explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-172435@lists.php.net to get a copy of this message
In using explode, with the list command, you will get errors if the number of variables is larger than the produced array by explode. For example: <?php $str = 'aa|bb|cc'; list($one, $two, $three, $four) = explode('|', $str); ?> To solve these cases, where you would like to assign empty strings to the extra variables (and eliminate errors), append a delimiter string to the string as follows. <?php $str = 'aa|bb|cc'; list($one, $two, $three, $four) = explode('|', $str . '|||'); ?> This way, the list variables will always be assigned. ---- Server IP: 208.69.120.55 Probable Submitter: 24.20.177.246 ---- Manual Page -- http://www.php.net/manual/en/function.explode.php Edit -- https://master.php.net/note/edit/99841 Del: integrated -- https://master.php.net/note/delete/99841/integrated Del: useless -- https://master.php.net/note/delete/99841/useless Del: bad code -- https://master.php.net/note/delete/99841/bad+code Del: spam -- https://master.php.net/note/delete/99841/spam Del: non-english -- https://master.php.net/note/delete/99841/non-english Del: in docs -- https://master.php.net/note/delete/99841/in+docs Del: other reasons-- https://master.php.net/note/delete/99841 Reject -- https://master.php.net/note/reject/99841 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#172435) next »