How to display certain number of words from a record?

I got good php tutorial to display certain number of words from database; in place of Database record you can use any other regular string.

 300) {
$ext = "... read more";
} else {
$ext = "";
}
function elliStr($s,$n) {
for ( $x = 0; $x < strlen($s); $x++ ) {
$o = ($n+$x >= strlen($s)? $s : ($s{$n+$x} == " "?
substr($s,0,$n+$x) . "..." : ""));
if ( $o!= "" ) { return $o; }
}
}

echo (elliStr("$text", 300)) . $ext;
?>
Share

Leave a Reply

Your email address will not be published. Required fields are marked *