Hello everyone, welcome to my today's post on PHP. In my last tutorial, we learned about "How to use vfprintf function in php". Hope you enjoyed that tutorial. Today we are going to learn about "How to user wordwrap function in php?". So, Let's start -
Returns a string with str wrapped at the column number specified by the optional width parameter. The line is broken using the (optional) break parameter.

wordwrap() will automatically wrap at column 75 and break using '\n' (newline) if width or break are not given.
If the cut is set to 1, the string is always wrapped at the specified width. So if you have a word that is larger than the given width, it is broken apart. (See second example).
** Note: The optional cut parameter was added in PHP 4.0.3
string wordwrap ( string str [, int width [, string break [, bool cut]]] )
Example 1:
$text = "The quick brown fox jumped over the lazy dog.";
$newtext = wordwrap($text, 20, "\n");
echo $newtext;
Outuput:
The quick brown fox jumped over the lazy dog.
Example 2:
$text = "A very long woooooooooooord.";
$newtext = wordwrap($text, 8, "\n", 1);
echo "$newtext\n";
Output:
A very long wooooooo ooooord.
Was this information useful? What other tips would you like to read about in the future? Share your comments, feedback and experiences with us by commenting below!
Like our site? Be a member of Coolajax fan page to get daily posts updates!
You May Like This Posts!
» How to strspn function works?
» How to stripslashes function work?
Tags:
word warp, word warp function, php word wrap, word wrap syntax, wordwrap tutorial, php tutorials
Total Read: 779 Topics