php The wordwrap() function means to wrap a string according to the specified length. The syntax is wordwrap(string,width,break,cut). If the function is successfully executed, the wrapped string will be returned. If it fails, Returns false.
How to use the wordwrap() function?
Function: wrap the string according to the specified length
Syntax:
wordwrap(string,width,break,cut)
Parameters:
string Required, specifies the string to be wrapped
width Optional, specifies the maximum line width, the default is 75
break Optional, specifies the use as a separator character (string breaking character), the default is "\n".
cut Optional, specifies whether to wrap words larger than the specified width: false -- default, no-wrap. true -- wrap lines.
Description: If the function is successfully executed, the wrapped string will be returned. If it fails, false will be returned.
php wordwrap() function example 1
<?php $i = "I love programming. It's fun."; $j = wordwrap($i,10,"<br>\n",true); echo $j; ?>
Output:
I love programmin g. It's fun.
php wordwrap() function example 2
<?php $i = "you can study php in php.cn"; $j = wordwrap($i); echo $j; ?>
Output:
you can study php in php.cn
The above is the detailed content of How to use php wordwrap function. For more information, please follow other related articles on the PHP Chinese website!