note 55610 added to function.str-split

From: Date: Mon, 08 Aug 2005 20:24:56 +0000
Subject: note 55610 added to function.str-split
Groups: php.notes 
Request: Send a blank email to php-notes+get-93272@lists.php.net to get a copy of this message
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; } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.str-split.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55610 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55610&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55610&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55610&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55610&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55610&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55610&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55610&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#93272) next »