This is a function I use to display the ellipses when I want to truncate and display a summary of a larger body of text.
<?php
function truncateString($intLength = 0, $strText = "") {
if ($intLength == 0) {
return $strText;
}
if(strlen($strText) > $intLength) {
preg_match("/[a-zA-Z0-9]{0, " . $intLength . "}/", $strText, $strNewText);
return ($strNewText . "...");
}
else {
return $strText;
}
}
?>
Tags: PHP