6000) { return false; } // cleanup $text=stripslashes($text); $text=ereg_replace("\r", " ", $text); $text=ereg_replace("\t", " ", $text); $text=ereg_replace("\n", " ", $text); while(ereg(" ", $text)) { $text=str_replace(" ", " ", $text); } $size = strlen($text); // what text size ? // put words in array $string = explode(" ",$text); $words = count($string); $a=1; // strip lines smaller than $width to an array for ($i = 0 ; $i < $words ; $i++) { if(strlen($output[$a].$string[$i])>=$width) { $a++; } $output[$a] .= $string[$i]." "; }; $i = -1; while($i132) { // limitation to 132 cols return false; } if($len>=$width) { return substr($text,0, $width); } $neededspaces = $width - $len; $availablespaces = explode(" ", $text); $availablespaces = count($availablespaces)-1; $ratio = $availablespaces / $neededspaces; $usablespaces = ""; if($ratio!=0) { if($neededspaces>=$availablespaces) { while(($width>=$len) && ($neededspaces>=0)) { $i = 0;// used as pointer inside the string while(($i<=$len) && ($neededspaces>=0) ) { // parse all string $temp=substr($text,$i,1); // get one letter if($temp==" ") { // is it a space ? $text=substr($text,0,$i)." ".substr($text,$i+1,$len);// insert another space $neededspaces--;// one space less $len = strlen($text); $i++; } $i++; } $len = strlen($text); } } else { while(($width>=$len) && ($neededspaces>=0)) { $i = 0;// used as pointer inside the string while(($i<=$len) && ($neededspaces>=0) ) { // parse all string $temp=substr($text,$i,1); // get one letter if($temp==" ") { // is it a space ? $text=substr($text,0,$i)." ".substr($text,$i+1,$len);// insert another space $neededspaces--;// one space less $len = strlen($text); $i++; } $i++; } $len = strlen($text); } } } $out=$text; return $out; } /* example code (provided with package */ $text = $HTTP_POST_VARS[text]; $width = $HTTP_POST_VARS[width]; $submit = $HTTP_POST_VARS[submit]; if($width>132 || $width<20) { $width=80; } if($text && $submit) { echo "
".justify_text($text, $width)."
"; } else { ?> PHPJustify By tobozo (c+)

Justify Now!

Width of column, in characters:

Paste text you want justified here (one paragraph at a time) :