How to crop a paragraph to a limited text?
Wednesday, October 17th, 2007here is the function:
function CropSentence ($strText, $intLength, $strTrail)
{
$wsCount = 0;
$intTempSize = 0;
$intTotalLen = 0;
$intLength = $intLength - strlen($strTrail);
$strTemp = “”;
if (strlen($strText) > $intLength) {
$arrTemp = explode(” “, $strText);
foreach ($arrTemp as $x) {
if (strlen($strTemp) <= $intLength) $strTemp .= ” ” . $x;
}
$CropSentence = $strTemp . $strTrail;
} else {
$CropSentence = $strText;
}
return $CropSentence;
}
to call the function
$strTemp = CropSentence($r[”event_description”], 150, “…”);
Posted by Suresh B