note 45070 added to function.str-split

From: Date: Tue, 24 Aug 2004 22:57:34 +0000
Subject: note 45070 added to function.str-split
Groups: php.notes 
Request: Send a blank email to php-notes+get-75236@lists.php.net to get a copy of this message
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; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.str-split.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+45070 Delete -- http://master.php.net/manage/user-notes.php?action=delete+45070&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+45070&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#75236) next »