note 79477 deleted from function.str-split by crell
| From: | crell@php.net | Date: | Wed, 29 Jun 2022 18:29:39 +0000 |
| Subject: | note 79477 deleted from function.str-split by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218682@lists.php.net to get a copy of this message | ||
Note Submitter: mohd at ba7rain dot net
----
this function can perform a reverse str_split. I write it for PHP4 but you can rename It for other
versions..
if ( !function_exists('str_split') ) {
function str_split($string,$split_length=1){
$sign = (($split_length<0)?-1:1);
$strlen = strlen($string);
$split_length = abs($split_length);
if ( ($split_length==0) || ($strlen==0) ){
$result = false;
//$result[] = "";
}
elseif ($split_length >= $strlen){
$result[] = $string;
}
else {
$length = $split_length;
for ($i=0; $i<$strlen; $i++){
$i=(($sign<0)?$i+$length:$i);
$result[] = substr($string,$sign*$i,$length);
$i--;
$i=(($sign<0)?$i:$i+$length);
if ( ($i+$split_length) > ($strlen) ){
$length = $strlen-($i+1);
}
else {
$length = $split_length;
}
}
}
return $result;
}
}