note 61928 deleted from function.str-split by crell
| From: | crell@php.net | Date: | Wed, 29 Jun 2022 18:29:09 +0000 |
| Subject: | note 61928 deleted from function.str-split by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218679@lists.php.net to get a copy of this message | ||
Note Submitter: carlosreche at yahoo dot com
----
For those who work with PHP < 5:
<?php
if (!function_exists("str_split")) {
function str_split($string, $length = 1) {
if ($length <= 0) {
trigger_error(__FUNCTION__."(): The the length of each segment must be greater then
zero:", E_USER_WARNING);
return false;
}
$splitted = array();
$str_length = strlen($string);
$i = 0;
if ($length == 1) {
while ($str_length--) {
$splitted[$i] = $string[$i++];
}
} else {
$j = $i;
while ($str_length > 0) {
$splitted[$j++] = substr($string, $i, $length);
$str_length -= $length;
$i += $length;
}
}
return $splitted;
}
}
?>