WordPress: How to Truncate the Length of Titles in Previous / Next Post Links

Here is the code I use to truncate the length of post titles in previous post / next post links on WordPress sites:

<?php
$prev_post = get_previous_post();
if($prev_post) {
   $prev_title = strip_tags(str_replace('"', '', $prev_post->post_title));
   $getlength = strlen($prev_title);
   $thelength = 25;
   echo '<a href="' . get_permalink($prev_post->ID) . '" title="' . $prev_title. '">&lsaquo;&nbsp;';
   echo substr($prev_title, 0, $thelength);
   if ($getlength > $thelength) echo "...";
   echo '</a>&nbsp;';
}

echo '&nbsp;|&nbsp;';

$next_post = get_next_post();
if($next_post) {
   $next_title = strip_tags(str_replace('"', '', $next_post->post_title));
   $getlength = strlen($next_title);
   $thelength = 25;
   echo '<a href="' . get_permalink($next_post->ID) . '" title="' . $next_title. '">';
   echo substr($next_title, 0, $thelength);
   if ($getlength > $thelength) echo "...";
   echo '</a>&nbsp;&rsaquo;';
}
?>

The result looks something like this:

« This is the title of th… | This is the title of th… »