Home >>PHP String Functions >PHP wordwrap() Function
PHP wordwrap() function is used to wraps any given input string into a given number of lines using a string break character. It braeks the line when it reaches to a defined length.
Syntax:
wordwrap($string, $width, $break, $cut);
Parameter | Description |
---|---|
string | This is a required parameter. This parameter defines the string to break up into lines. |
width | This is an optional parameter. This parameter defines the maximum line width. |
break | This is an optional parameter. This parameter defines the characters to use as break. |
cut | This is an optional parameter. This parameter defines whether words longer than the specified width should be wrapped. |
Here is an example of wordwrap() function in PHP:
<html> <body> <?php $str = "This is an example text: abcdefghijklmnop"; echo wordwrap($str,10,"<br>"); ?> </body> </html>
Here is an another example of wordwrap() function in PHP:
<html> <body> <?php $str = "This is an example text: abcdefghijklmnopqrstuvwxyz"; echo wordwrap($str,15,"<br>",TRUE); ?> </body> </html>