PHP.nl

wordwrap

wordwrap

Wraps a string to a given number of characters

string **wordwrap** string $string int $width string $break bool $cut_long_words

Wraps a string to a given number of characters using a string break character. Strings wrap after a space (U+0020) character unless is set to true. cut_long_words

stringThe input string.

widthThe number of characters at which the string will be wrapped.

break The line is broken using the optional parameter. It must not be an empty string. break

cut_long_words If the is set to true, the string is always wrapped at or before the specified . So if you have a word that is larger than the given width, it is broken apart. (See second example). When false the function does not split the word even if the is smaller than the word width. cut_long_words``width``width

Returns the given string wrapped at the specified length.

If is an empty string, a is thrown. break``ValueError

Voorbeeld: example

<?php
$text = "The quick brown fox jumped over the lazy dog.";
$newtext = wordwrap($text, 20, "<br />\n");

echo $newtext;
?>
The quick brown fox<br />
jumped over the lazy<br />
dog.

Voorbeeld: example

<?php
$text = "A very long woooooooooooord.";
$newtext = wordwrap($text, 8, "\n", true);

echo "$newtext\n";
?>
A very
long
wooooooo
ooooord.

Voorbeeld: example

<?php
$text = "A very long woooooooooooooooooord. and something";
$newtext = wordwrap($text, 8, "\n", false);

echo "$newtext\n";
?>
A very
long
woooooooooooooooooord.
and
something

nl2br``chunk_split