Converts a string to an array. If the optional $num parameter is specified, the returned array will be broken down into chunks with each being split in $num length.
This fuction is almost the same as the fuction str_split included in php5.
<?php
function strsplt($thetext,$num)
{
if (!$num)
{
$num=1;
}
$arr=array();
$x=floor(strlen($thetext)/$num);
while ($i<=$x)
{
$y=substr($thetext,$j,$num);
if ($y)
{
array_push($arr,$y);
}
$i++;
$j=$j+$num;
}
return $arr;
}
?>
(PHP 5)
str_split -- Convert a string to an array
Description
array str_split ( string string [, int split_length])
Converts a string to an array. If the optional split_length parameter is specified, the returned array will be broken down into chunks with each being split_length in length, otherwise each chunk will be one character in length.
FALSE is returned if split_length is less than 1. If the split_length length exceeds the length of string, the entire string is returned as the first (and only) array element.
Array
(
[0] => H
[1] => e
[2] => l
[3] => l
[4] => o
[5] =>
[6] => F
[7] => r
[8] => i
[9] => e
[10] => n
[11] => d
)
Array
(
[0] => Hel
[1] => lo
[2] => Fri
[3] => end
)
ROMEL CUZON wrote :1143
Wondering about the error appear when I migrate my sample program from home to office . This function I made was derive after I realize that it was not included in PHP4 that is in our office. I use PHP5 at home. I think the first sample comment above is the shortcut function.