Intro
Finding URLs in text and transforming them into links is handy tool to have around. WordPress does this via the make_clickable function. I extracted this into a stand alone PHP class called MakeItLink.
MakeItLink – Detecting URLs In Text And Making Them Links is the original version of the code and initial blog post.
Source
The MakeItLink class can be viewed as PHP highlighted source code or the plain text version.
Example
require dirname( __FILE__ ) . '/makeitlink.php'; $example = 'My home page is at http://josephscott.org/'; $with_links = MakeItLink::transform( $example ); echo $with_links;
Change Log
0.2.0 – 26 Oct 2009
- Sync with WordPress 2.9 make_clickable()
First, thanks for making this class available. Unfortunately it is only working for me with complete URLs, e.g. http://www.test.com. If I have something simply like http://www.test.com that is not coverted to a clickable link. I’m pretty darn sure I copied and pasted without error. Any ideas what might be happening? Thanks. PS – I’m using it within a CodeIgniter app, but I figured PHP is PHP and it should work (I get no errors or anything).
Right, that was intentional. There are some improvements that could go into this.
Quick followup — The “simple” URL did not have the “http://” in the text I entered. :)