Auto-Linking URLs with PHP

A week or so ago I was working on a bug in the auto-linking code for Laconica, the software that powers Indenti.ca. Squashing that particular bug wasn’t too hard, but I wanted to take the functionality a step further (closer to the calibre of Gmail) and it turns out, writing robust auto-linking code is more difficult than it initially seems. So I played with it a little at a time here and there, testing as many edge cases as I could think of. The result is a function that’s more robust than most URL auto-linking code I’ve come across.

I still need to add support of internationalized TLDs and HTML. So, although it only works with plain text for now, I think it’s off to a good start. Check out the demo or download the source.

No related posts.

Comments

4 Responses to “Auto-Linking URLs with PHP”

  1. Tiago Faria on January 31st, 2009 9:31 pm

    Hi,

    If you had a laconica tag/category I would really like to aggregate your posts on Planet Laconica (http://laconi.ca/planet).

    Let me know if you’re interested, and feel free to delete this comment.

    Tiago

  2. buggedcom on May 26th, 2009 4:35 am

    Hi,

    Just wondering if you had thought about using a LGPL/MIT/BSD license instead of GPL so it could be used in commercial applications.

  3. buggedcom on May 26th, 2009 4:42 am

    I suggest that the callback function is optional? unless I’m greatly missing the point.

  4. Sean Murphy on May 31st, 2009 11:22 am

    @buggedcom I’m not interested in moving away from the GPL in general. If you would like to use the software in a commercial application it’s possible we could negotiate a price for a commercial license.

    What would the function do if there were no callback? Return an array of URLs? I suppose that’s possible, but you could almost just as easily collect the URLs in an array using a callback function and a global variable. What did you have in mind?

Leave a Reply