Or... something like this for a bit more expandability.
Overbleed, what this means is that you can set the maxLength for each use of this function.
<?php
function cut_str($maxLength,$string){
$suffix = '...';
$finalStr = '';
if(strlen($string) > $maxLength) {
while($string{$maxLength} != ' '){
$finalStr .= $str{$maxLength};
$maxLength++;
}
return substr($string,0,$maxLength).$suffix;
} else {
return $string;
}
}
$postTitle = 'This is my post title, just a filler really.';
echo cut_str(23,$postTitle);
?>
Max length is now set to 23 and the result becomes => "This is my post title, just..."
[edit] Nice code Paul ^5!