note 41082 deleted from function.str-split by nlopess
| From: | nlopess@php.net | Date: | Thu, 29 Apr 2004 13:21:19 +0000 |
| Subject: | note 41082 deleted from function.str-split by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-69001@lists.php.net to get a copy of this message | ||
Note Submitter: aznpride669@hotmail.com
----
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;
}
}
?>