note 41082 added to function.str-split

From: Date: Mon, 29 Mar 2004 20:30:28 +0000
Subject: note 41082 added to function.str-split
Groups: php.notes 
Request: Send a blank email to php-notes+get-67339@lists.php.net to get a copy of this message
I feel this to be quite accurate to the actual function. <?php // Define str_split(), if one isn't using PHP5. if (!function_exists('str_split')) { function str_split($str, $length = 1) { // Return false if parameter isn't string, length isn't numeric, or length is 0. if (!is_string($str)|| !is_numeric($length) || $length == 0) { return FALSE; } // Define array to be used to split. $strArr = array(); // Loop through all characters and stick them in the array. for ($i = 0; $i < strlen($str); $i += $length) { if (strlen(substr($str, $i)) < $length) { $strArr[] = substr($str, $i); } else { $strArr[] = substr($str, $i, $length); } } // Return the array. return $strArr; } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.str-split.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+41082 Delete -- http://master.php.net/manage/user-notes.php?action=delete+41082&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+41082&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#67339) next »