wordwrap() function in PHP is used to wrap a string to a specified number of characters. It inserts line breaks at the appropriate points to ensure that no line of text exceeds the specified width.
Here is the syntax of the
wordwrap(string, width, break, cut)
The first argument is the string to be wrapped. The second argument is the width at which to wrap the text. The third argument is the character or string to use as a line break. By default, the line break is a newline character ("\n"). The fourth argument is a boolean value that determines whether to cut words that are too long to fit on a line. By default, words are not cut.
Here is an example of how to use
$text = "This is a long piece of text that needs to be wrapped."; $wrapped_text = wordwrap($text, 20, "\n"); echo $wrapped_text;
This will output:
This is a long piece of text that needs to be wrapped.
In this example, the
wordwrap() function has wrapped the text so that no line of text exceeds 20 characters. The line breaks are inserted using the newline character "\n".