I warn you now I'm new to php ! What I would like to do is limit the title outputted by . get_the_title() . to say 30 characters

I have this in my theme:
Code:
		<ul>
			<?php
				if (is_single()) {
					$posts = get_posts('numberposts=5&orderby=post_date');
				} else {
					$posts = get_posts('numberposts=5&orderby=rand');
				}
				foreach($posts as $post) {
					setup_postdata($post);
					echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
				}
				$post = $posts[0];
			?>
		</ul>
I have added a function to my theme to replace 'the_title' to display shorter titles elsewhere but if I try to use this function in the above code eg. change 'get_the_title' to my 'trim_title' function all goes pear shaped.

Any help would be really appreciated