note 45071 deleted from function.str-split by aidan

From: Date: Thu, 26 Aug 2004 23:15:50 +0000
Subject: note 45071 deleted from function.str-split by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-75387@lists.php.net to get a copy of this message
Note Submitter: Shining Arcanine ---- I realized that when the split length was longer than the string length or the split length was below 1 the str_split() function in PHP5 returns the string as the first entry of the array rather than returning the string as a string like my revision to Rick's PHP does. This should resolve that: <?php function str_split($str, $len=1) { $input_len = strlen($str); if ($len < 1 or $len > $input_len) return array($string); $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 (#75387) next »