Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Aqui vai uma alternativa da função str_split() pra quem trabalha com versões anteriores ao PHP 5.
/**
* array str_split ( string String [, integer Length ] )
*
* Carlos Reche <carlosreche@yahoo.com>
*/
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 = 0;
while ($str_length > 0) {
$splitted[$j++] = substr($string, $i, $length);
$str_length -= $length;
$i += $length;
}
}
return $splitted;
}
}Carregando comentários...