// text_wrap( $text, $max_width, $html_type )
// $text - Text to be formatted (a string)
// $max_width - Column on which to wrap
// $html_type - Should be "PRE" or "BLOCKQUOTE"
// Written by Jeffrey D. Webster of Mirada Innovations.
// This particular function was written for our clients, so that
// they could embed quotations from persons being interviewed
// without having to pay much attention to how the text was
// Coming soon: Full justification function for <PRE> blocks.
// Version 1.0
Function text_wrap( $text, $max_width, $html_type )
// $cnt keeps track of the position of the last break
$cnt = 0;
if (!strcmp("PRE", $html_type))
$line_break = "\n";
$line_break = "<BR>\n";
for ($i = $max_width; $i < strlen($text); $i += $max_width)
$width = $max_width;
while ($text[$i] != ' ' && $text[$i] != '\n' && $text[i] != '\t')
echo substr($text, $cnt, $width),$line_break;
$cnt = $i+1;
$last_line = substr($text, $cnt);
if ($last_line != ' ')
echo substr($text, $cnt);
echo substr($text, $cnt+1);
// Do a little test.
// An arbitrary string ;)
$line = "\"When considering the use of a server side";
$line = "$line language, such as php3, you have to weigh";
$line = "$line the load on your server against the benefits";
$line = "$line of the language. For many, especially with";
$line = "$line regards to php3, the benefits are worth the";
$line = "$line sacrifice. For some tasks it is unimaginable";
$line = "$line how difficult they would be without server side";
$line = "$line scripting. There is certainly something to be";
$line = "$line said for web content that is dynamic -- it";
$line = "$line keeps people coming back.\" -- The Webmaster";
text_wrap($line, 60, "BLOCKQUOTE");
Comments or questions?
PX is running PHP 5.2.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.