The following function is essentially the third in a series that look at creating links from URLs, hashtags, and usernames. Intended for Twitter, the same principle applies across multiple networks. THe function's primary purpose is to support the article "Retrieve Your Twitter Follow Count (and Other Data) in Plain Text With WordPress Shortcode or PHP", published here.
We use and reference this function for both PHP and WordPress applications.
It's a very basic function with simple expressions... but it'll suffice for most of the uses we have for it.