note 30306 added to function.explode
| From: | dan at boxuk dot com | Date: | Thu, 13 Mar 2003 16:11:07 +0000 |
| Subject: | note 30306 added to function.explode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-45220@lists.php.net to get a copy of this message | ||
Here's a function I find useful from time to time.... When you're assigning the results of
an explode() to a list(x,y,z) of values, you'll get an error/warning in PHP if your explode()
didn't return the same number of arguments as your list... So you can use the following simple
function to always return the correct number of elements in your array:
// explodeForce - like explode, but rather than just 'limit' the explosion to
// the number of values, it also ensures that this number of elements are
// present in the output array - v.useful for when assigning an explode
// to a list($a,$b,$c)
function explodeForce($sep, $array, $number_values, $pad = '')
{
return array_pad(explode($sep, $array, $number_values), $number_values, $pad);
}
--
http://www.php.net/manual/en/function.explode.php
http://master.php.net/manage/user-notes.php?action=edit+30306
http://master.php.net/manage/user-notes.php?action=delete+30306
http://master.php.net/manage/user-notes.php?action=reject+30306