wordwrap function in php

 Published April 23,2010 in PHP

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 function in php
 

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

- How to write wordwrap() Function:

string wordwrap ( string str [, int width [, string break [, bool cut]]] )

- Write a live Example of wordwrap() function:

Example 1:

$text = "The quick brown fox jumped over the lazy dog.";
$newtext = wordwrap($text, 20, "\n");
echo
$newtext;

Demo

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";

Demo

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!

recommended-tutorial You May Like This Posts!

» trim function in php

» How to strspn function works?

» How to stripslashes function work?

» How to substr_count function works?

» How to strcasecmp function works?

  tuts_view Total Read: 779
blog comments powered by Disqus

Topics

Coolajax Fans

coolajax fan page on Facebook