just a quick question.. anyone got a quick script or link for creating excerpts?
| SitePoint Sponsor |



just a quick question.. anyone got a quick script or link for creating excerpts?
Aaron Smith
smithaaronlee.net
you mean like how to show the first 50 characters of a message?



exactly.
Aaron Smith
smithaaronlee.net
substr()
if you want a smarter version that wont cut half a word off, i took this from the user comments on php.net
PHP Code:function myfragment($str, $n, $delim='...') {
$len = strlen($str);
if ($len > $n) {
preg_match('/(.{' . $n . '}.*?)\b/', $str, $matches);
return rtrim($matches[1]) . $delim;
}
else {
return $str;
}
}
Bookmarks