note 45070 deleted from function.str-split by aidan

From: Date: Thu, 26 Aug 2004 23:15:54 +0000
Subject: note 45070 deleted from function.str-split by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-75385@lists.php.net to get a copy of this message
Note Submitter: Shining Arcanine ---- To improve on Rick's version I've added a check for the case in which the string length is less than the split length and changed it to return the string rather than false when the string length is greater than the split length or the split length is less than one: <?php function str_split($str, $len=1) { $input_len = strlen($str); if ($len < 1 or $len > $input_len) return $str; $str_ary = array(); // don't use substr unless you have to if($len == 1) for($cursor = 0; $cursor < $input_len; $cursor++) $str_ary[] = $str{$cursor}; else for ($cursor = 0; $cursor < $input_len; $cursor += $len) $str_ary[] = substr($str, $offset, $len); return $str_ary; } ?>

« previous php.notes (#75385) next »