php wordwrap() function
Translation results:
UK [wə:d ræp] US [wɚd ræp]
n.Automatic line wrapping
php wordwrap() functionsyntax
How to use wordwrap() function?
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 characters will be returned. String, or false if failed.
Function: Wrap the string according to the specified length
Syntax: wordwrap(string,width,break,cut)
Parameters:
Parameters | Description |
string | Required, specifies the string to be wrapped |
width | Optional, specifies the maximum line width, the default is 75 |
break | Optional, specifies the character used as a separator (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() functionexample
<?php $i = "I love programming. It's fun."; $j = wordwrap($i,10,"<br>\n",true); echo $j; ?>
Run instance»
Click the "Run instance" button to view the online instance
Output:
I love programmin g. It's fun.
<?php $i = "you can study php in php.cn"; $j = wordwrap($i); echo $j; ?>
Run Instance»
Click the "Run Instance" button to view the online instance
Output:
you can study php in php.cn