The wordwrap() function in PHP wraps a string into new lines when it reaches a specific length.
Syntax
wordwrap(str,width,break,cut)
Parameters
str − The specified string
width − The maximum line width. The default is 75
break − The characters to use as break. The default is "\n"
cut − If set to TRUE, the string is always wrapped at or before the specified width
Return
The wordwrap() function returns the string broken into lines on success, or FALSE on failure.
Example
The following is an example −
<?php $str = "Java is a programming language developed by James Gosling in 1994."; $res = wordwrap($str, 15, "<br />\n"); echo $res; ?>
Output
The following is the output −
Java is a<br /> programming<br /> language<br /> developed by<br /> James Gosling<br /> in 1994.