What is PhpDig?
PhpDig is a PHP MySQL based
Web Spider & Search Engine.



wordwrap — Breaks a string into multiple lines.


string wordwrap(string[, width][, break][, cut]);
string string: String to break into lines
int width (optional): Maximum width of the lines
string break (optional): One or more characters to be used as the break between lines
int cut (optional): How long words are broken


String; FALSE on error


wordwrap() breaks a string into one or more lines. The default behavior for the function is to create lines of 75 characters (or fewer), separated by newlines. Each line breaks only on a whitespace character - when the line is broken, the character that the line was broken on is replaced with a newline.

This function is quite flexible - the width of the lines can be controlled with the width argument, while the character (or characters) used to end the lines can be set with the optional break argument.

Additionally, the cut argument allows wordwrap() to break up words that are longer than the length specified in the width argument.


wordwrap() may leave whitespace at the beginning of a line.


PHP 4.0.2+ (optional argument was added in PHP 4.0.3)

See also

To break text into fixed-length lines:


To convert newlines into line-break tags:



Example 1246. Wrap a block of text

// From "The Private Life of Genghis Khan" by Douglas Adams
// Based on an original sketch by Douglas Adams and Graham Chapman
$text = <<<_TPLoGK_
"All those letters to answer. You'd be astonished at the demands
people try to make on my time you know." He slouched moodily against
his horse. "Would I sign this, would I appear there. Would I please
do a sponsored massacre for charity. So that usually takes till at
least three, then I had hoped to get away early for a long weekend.
Now Monday, Monday..."

echo wordwrap($text, 60, '<br />');

Example 1247. Format a block of text in an irritating fashion

// From "Riding the Rays" by Douglas Adams
$text = <<<_RtR_
It comes right up to you and laughs very hard in your face in a
highly threatening and engaging manner. In fact it's not so much
a country as such, more a sort of thin crust of semi-demented
civilisation caked around the edge of a vast, raw wilderness,
full of heat and dust and hopping things.

/* My high school typing teacher informed me that the average
 * word was 8 characters in length - let's see how that looks
    * for formatting. :)
echo wordwrap($text, 8, '<br />', TRUE);

PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing (Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch). This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at The authors of this book have elected not to choose any options under the OPL. This online book was obtained from and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4 for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All persons and entities shall have neither liability nor responsibility to any person or entity with respect to any loss or damage arising from the information contained in this book.

Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.