Parsing tweets with PHP

Sunday 14th March

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!


Tweet

Comments

Mon 15 Mar 2010 08:07

Russell Heimlich

Russell Heimlich said:

Awesome stuff! I used to write my own but these look a lot more accomodating.

Mon 15 Mar 2010 10:15

Five Minute Argument

Five Minute Argument said:

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!

Tue 21 Sep 2010 17:47

Ante Vukorepa

Ante Vukorepa said:

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.

Wed 27 Oct 2010 03:29

Atlanta Web Design Company

Atlanta Web Design Company said:

Good work! like your effort.

Mon 4 Apr 2011 18:29

jiro brasen

jiro brasen said:

This is a wonderful post. Thank you for having it posted here.

Leave a comment