Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Illidan

Função str_split

Recommended Posts

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;
}
}

Compartilhar este post


Link para o post
Compartilhar em outros sites

Valeu, pessoal! :)

 

Também gostei da idéia de recriar mais funções do PHP 5 pra quem ainda tem que usar PHP 4.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.