UPDATED, once again:
Tightened up the code a bit.
I've also adjusted the $title string length so that it will show the full 50 chars topic title in the URL, instead of just the truncated 30.
The default subject title is 50 chars. My setting of "70" should more than cover that.
The main intentions of this modification are to 1) better sanitize the URL, and 2) improve the URL for the user to know where he's about to arrive before clicking the link... and SEO.