I added some HTML→Twitter microsyntax routines to my helpers library: https://github.com/barnabywalters/php-helpers