Argument List:
- $mystring: The text
- $limit: length of the string upto which string is to be truncate.
- $pad: The string which shows continuation. Default it takes 3 dots (...) .
function truncate_text($mystring, $limit = 153,$pad ="..."){
if(strlen($mystring) < $limit)
return $mystring;
$rstring = substr($mystring,0,$limit);
$no_of_chars = strrpos($rstring," ");
if($no_of_chars < $limit)
$rstring = substr($mystring,0,$no_of_chars).$pad;
return $rstring;
}
No comments:
Post a Comment