I use this function to make excerpt of text and link to full content. Now when reach the count of symbols(letters) is cutting the word. I don't want to cut the on first, second or any word. How to check and make excerpt before or after the word? Here is function that I use
function getExcerpt($str, $startPos=0, $maxLength=150) {
if(strlen($str) > $maxLength) {
$excerpt = substr($str, $startPos, $maxLength-3);
$lastSpace = strrpos($excerpt, ' ');
$excerpt = substr($excerpt, 0, $lastSpace);
$excerpt .= '...';
} else {
$excerpt = $str;
}
return $excerpt;
}