A port of Remy Sharp’s excellent ‘ify’ code.
Just a quick post to announce my release of a PHP port of Remy Sharp’s ‘ify’ script, a very simple chunk of code to auto-link the following parts of a tweet:
such that this text:
I wrote an open letter to @taylorswift13 http://stuffandnonsense.co.uk/s/1239 #sn_1239 (RT please)
becomes this:
I wrote an open letter to @taylorswift13 http://stuffandnonsense.co.uk/s/1239 #sn_1239 (RT please)
Remy’s code is nothing more than 3 regular expressions, so is highly portable. There are many other very similar solutions out there, but Remy’s is the best at handling edge-cases that I’ve come across. I’ll endeavour to update this port whenever the original is updated. All feedback is welcome!
Thanks, Russell. All the work is in Remy’s regexps which are much better than anything else I've seen; I might write a detailed analysis of them if I think it’s worth it!
I've improved the URL regexp a bit, it was pretty limited:
([a-z]*(?:\:\/\/)*[a-z0–9-_]+(?:\.[a-zA-Z0–9-_:~%&\?\+#\=\/]+)+[^:\.,\)\s*$])
It now handles URLs not prefixed by "http://", but eliminates spurious ones ("foo..something" or "foo…something" or… you get the idea). I ran across a bug or two with it and fixed those as well.
Hope they work out for you.
Mon 15 Mar 2010 08:07
Russell Heimlich said:
Awesome stuff! I used to write my own but these look a lot more accomodating.