note 99841 deleted from function.explode by googleguy

From: Date: Sat, 12 Jan 2013 09:53:41 +0000
Subject: note 99841 deleted from function.explode by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-192977@lists.php.net to get a copy of this message
Note Submitter: mvpetrovich ---- 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.

« previous php.notes (#192977) next »