wordwrap
Function • Params and return types changed in PHP 8.0
Wraps a string to a given number of characters.
wordwrap Function synopsis
wordwrap(
string $string,
int $width = 75,
string $break = "\n",
bool $cut_long_words = false
): string
Parameters
$string
Typestring
The input string.
$width
OptionalTypeintDefault value75
The number of characters at which the string will be wrapped.
$break
OptionalTypestringDefault value"\n"
The line is broken using the optional $break parameter.
It must not be an empty string.
$cut_long_words
OptionalTypeboolDefault valuefalse
If the $cut_long_words is set to true, the string is
always wrapped at or before the specified $width. So if you have
a word that is larger than the given width, it is broken apart.
(See second example). When false the function does not split the word
even if the $width is smaller than the word width.
Return value
Typestring
Returns the given string wrapped at the specified length.
Changes to the wordwrap Function
PHP 8.0
- Return type added:
string - Parameter name of parameter #1 changed:
$strto$string - Parameter type added for parameter #1 (
$string):string - Parameter type added for parameter #2 (
$width):int - Parameter default value added for position #2 (
$width):75 - Parameter type added for parameter #3 (
$break):string - Parameter default value added for position #3 (
$break):"\n" - Parameter name of parameter #4 changed:
$cutto$cut_long_words - Parameter type added for parameter #4 (
$cut_long_words):bool - Parameter default value added for position #4 (
$cut_long_words):false
wordwrap(
- $str,
+ string $string,
- $width,
+ int $width = 75,
- $break,
+ string $break = "\n",
- $cut
+ bool $cut_long_words = false
- )
+ ): string wordwrap Function Availability
wordwrap Function Availability| PHP Version | Availability |
|---|---|
| PHP 8.6Upcoming Release | Yes |
| PHP 8.5Supported (Latest) | Yes |
| PHP 8.4Supported | Yes |
| PHP 8.3Security-Fixes Only | Yes |
| PHP 8.2Security-Fixes Only | Yes |
| PHP 8.1Unsupported | Yes |
| PHP 8.0Unsupported | Yes |
| PHP 7.4Unsupported | Yes |
| PHP 7.3Unsupported | Yes |
| PHP 7.2Unsupported | Yes |
| PHP 7.1Unsupported | Yes |
| PHP 7.0Unsupported | Yes |
| PHP 5.6Unsupported | Yes |
| PHP 5.5Unsupported | Yes |
| PHP 5.4Unsupported | Yes |
| PHP 5.3Unsupported | Yes |