note 55610 deleted from function.str-split by aidan

From: Date: Sat, 04 Feb 2006 07:14:33 +0000
Subject: note 55610 deleted from function.str-split by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-102965@lists.php.net to get a copy of this message
Note Submitter: Jason <support [at] ejdude [dot] com> ---- My version of str_split() for PHP < 5: <?php if ( !function_exists('str_split') ) { function str_split($string, $split_length = 1) { $array = array(); $strlen = strlen($string); // Original function returns FALSE if $split_length is < 1 if ( $split_length < 1 ) { return false; } // If the split length will let the string fit in one array key, don't even bother if ( $split_length >= $strlen ) { return array($string); } for ( $i = 0, $key = 0, $count = 0; $i < $strlen; $i++, $count++ ) { // Count keeps track of when we've reached the split length if ( $count >= $split_length ) { $count = 0; // When the split length is reached, use the next key $key++; } // Protection against E_NOTICE undefined offset // isset() is faster than array_key_exists() if ( isset($array[$key]) ) { $array[$key] .= $string{$i}; } else { $array[$key] = $string{$i}; } } return $array; } } ?>

« previous php.notes (#102965) next »