Função PHP chunk_split()
Exemplo
Divida a string após cada caractere e adicione um "." após cada divisão:
<?php
$str = "Hello world!";
echo chunk_split($str,1,".");
?>
Definição e uso
A função chunk_split() divide uma string em uma série de partes menores.
Nota: Esta função não altera a string original.
Sintaxe
chunk_split(string,length,end)
Valores de parâmetro
Parameter | Description |
---|---|
string | Required. Specifies the string to split |
length | Optional. A number that defines the length of the chunks. Default is 76 |
end | Optional. A string that defines what to place at the end of each chunk. Default is \r\n |
Detalhes técnicos
Valor de retorno: | Retorna a string dividida |
---|---|
Versão do PHP: | 4+ |
Mais exemplos
Exemplo
Divida a string após cada sexto caractere e adicione um "..." após cada divisão:
<?php
$str = "Hello world!";
echo chunk_split($str,6,"...");
?>
❮ Referência de String PHP