PHP wordwrap() Function
Example
Wrap a string at a specified length:
\n"); ?>Run Example »
Definition and Usage
The wordwrap() function wraps a string at a specified length.
**Note:** This function may leave spaces at the beginning of a line.
Syntax
wordwrap(
string,width,break,cut
)
| Parameters | Description |
|---|---|
| string | Required. Specifies the string to wrap. |
| width | Optional. Specifies the maximum line width. Default is 75. |
| break | Optional. Specifies the character used as the break separator (the string break character). Default is "\n". |
| cut | Optional. Specifies whether to wrap words longer than the specified width:
|
Technical Details
| Return Value: | On success, returns the wrapped string. On failure, returns FALSE. |
|---|---|
| PHP Version: | 4.0.2+ |
| Changelog: | In PHP 4.0.3, the cut parameter was added. |
More examples
Example 1
Using all parameters:
n",TRUE); ?>Run Example »
Example 2
Wrap a string:
The HTML output of the above code is as follows (view source):
An example of a
long word is:
Supercalifragulistic
The browser output of the above code is as follows:
An example of a long word is: Supercalifragulistic
Run Example »
PHP String Reference Manual