Hi,
try following:
function word_break($input, $length, $tru=0) {
if($tru == 1) {
$a = explode(" ", $input);
$buffer = "";
for($i=0; $i<count($a); $i++) {
if(strlen($buffer) < $length) {
$buffer .= " ".$a[$i];
} else {
break;
}
}
} else {
$chop = strlen($input)-$length;
$buffer = substr($input, 0, "-".$chop);
}
return $buffer."...";
}
$string = "i want to break this line as";
echo word_break($string, 8, 0); //Returns "i want t..."
echo word_break($string, 8, 1); //Returns "i want to..."
I hope it helps,
firemouse2001