Função PHP wordwrap()
Exemplo
Envolva uma string em novas linhas quando atingir um comprimento específico:
<?php
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"<br>\n");
?>
Definição e uso
A função wordwrap() envolve uma string em novas linhas quando atinge um comprimento específico.
Nota: Esta função pode deixar espaços em branco no início de uma linha.
Sintaxe
wordwrap(string,width,break,cut)
Valores de parâmetro
Parameter | Description |
---|---|
string | Required. Specifies the string to break up into lines |
width | Optional. Specifies the maximum line width. Default is 75 |
break | Optional. Specifies the characters to use as break. Default is "\n" |
cut |
Optional. Specifies whether words longer than the specified width should be wrapped:
|
Detalhes técnicos
Valor de retorno: | Retorna a string dividida em linhas em caso de sucesso ou FALSE em caso de falha. |
---|---|
Versão do PHP: | 4.0.2+ |
Registro de alterações: | O parâmetro cut foi adicionado no PHP 4.0.3 |
Mais exemplos
Exemplo
Usando todos os parâmetros:
<?php
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"<br>\n",TRUE);
?>
Exemplo
Enrole uma string em novas linhas:
<?php
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15);
?>
A saída HTML do código acima será (View Source):
<!DOCTYPE html>
<html>
<body>
An example of a
long word is:
Supercalifragulistic
</body>
</html>
A saída do navegador do código acima será:
An example of a long word is: Supercalifragulistic
❮ Referência de String PHP