wordwrap
Wraps a long string at word boundaries.
Syntax
wordwrap(string $string, int $width = 75, string $break = "\n", bool $cut_long_words = false): stringParameters
| Parameter | Type | Description |
|---|---|---|
| $string | string | The source string. |
| $width | int | Optional. The maximum line length. |
| $break | string | Optional. What to insert at the break. |
| $cut_long_words | bool | Optional. `true` breaks words longer than the width. |
Return value
stringThe wrapped string.
Examples
Lines no longer than 15 characters:
<?php
echo wordwrap('The quick brown fox jumps over the lazy dog', 15);Output:
The quick brown
fox jumps over
the lazy dogNotes
The function counts bytes, so for non-ASCII text the width comes out at half of what you expect.
See also
In the tutorial
- Strings — Working with strings in PHP — quotes, concatenation, length, searching, replacing and multibyte functions.