Automatically Linkify Text with PHP Regular Expressions

Every now and then I come across a link I’d just really like to share.  I could go post it on facebook or something but the truth is as far as programming goes, my friendlist just wouldn’t really care much.  So I thought to myself, hey PHP is stuff, I’ll post it up here.

Admittedly, working with regular expressions has not occurred very often for me and as such is a weakness as far as my PHP skills go.  Lucky for me the internet is full of helpful programmers more than happy to lend a hand.

Recently for a project I was working on I really wanted a way to give users the option to have inputted text automatically turn into a link (like you may have seen on twitter when using the # or @ sign) The most important thing when designing a front end to be used by people of unknown technical ability is just to make things easy for them.  Specifically, I wanted to have those fun # @ for tags and messaging but I also wanted my site to recognize when a user inputted a link.  No matter if that link was formed correctly (http://FoodBeerStuff.com) or just alluded to (FoodBeerStuff.com).

Turns out using regular expressions is a great way to get this functionality.  Like I said though, working with such is a clear weakness of mine.  Lucky for me I found Brian Muse over at buildinternet.com.   His post not only cleared a few things up for me but more or less did exactly what I was looking for right out of the box.  After reading it was a very simple matter for me to get things going on my own project.   So thanks Brian, it is appreciated.

You can find his write up here (Automatically Linkify Text with PHP Regular Expressions)

Leave a Reply

Your email address will not be published.

4 + 12 =

This site uses Akismet to reduce spam. Learn how your comment data is processed.