Why reinvent the wheel when you got t'internet! http://www.sitepoint.com/forums/showthread.php?t=181025&highlight=Shorten+URL
Code:
function wrapWord($word) {
static $limit = 30;
if(strlen($word) <= $limit)
return $word;
return "<a href=\"".$word."\">".substr($word, 0, ($limit + 3) >> 1).'...'.substr($word, -($limit - 3) >> 1)."</a>";
}