PHP wordwrap() Function
PHP wordwrap() Function
The wordwrap() Function wraps a string to a given number of characters using a string break character.
Syntax
wordwrap ( string $str [, int $width [, string $break [, bool $cut ]]] )
Parameter
str(required)- This parameter specifies the input string.
width(optional)- This parameter represents the number of characters at which the string will be wrapped. The default value for this parameter is 75.
break(optional)- This parameter specifies the characters to use as break. The default value is "\n".
cut(optional)- It specifies whether words longer than the specified width should be wrapped or not. If the parameter is set to TRUE, the string is always wrapped at or before the specified width else for false the function does not split the word
Return
This function returns the given string wrapped at the specified length on success or returns false on failure.
Example 1
Output
Before specifying the width function... The PHP Function used in this example: wordwrap() Function After specifying the width parameter as 45... The PHP Function used in this example: wordwrap() Function
Example 2
Output
String: Hello woooooooooooorld. After the wordwrap() function New String: Hello wooooooo ooooorld .
Example 3
Output
String: Hello woooooooooooorld. Hello PHHHP! After the wordwrap() function New String: Hello woooooooooooorld. Hello PHHHP!
Example 4
Output
String: Hello woooooooooooorld. Hello PHHHP! After the wordwrap() function New String: Hello woooooooooooorld. Hello PHHHP!