I've been aware of the shortcomings of the the autolinking feature for quite some time now; the main problems that autolinking had (that Allen had mentioned earlier and dodo recently brought back to my attention) is that autolinking would create autolinks of links.

A quick background: Autolinking allows you to associate words in your entries to websites; whenever that word appears in your journal, it links. For example, I have an autolink for the word AudioMatch. (You see what it did?)

The problem is when I wanted to do something like this directly in my entry:
I love <a href="http://www.audiomatch.net/?view&user=roy">my AudioMatch</a>
The autolinking feature would create the following HTML:
I love <a href="http://www.audiomatch.net/?view&user=roy">my <a href="http://www.audiomatch.net">AudioMatch</a></a>
Basically the solution required that autolinks ignore data already existing between <a> tags. But how to do this? Originally I was thinking I could use some really complex pattern matching using preg_replace(), but that would require me reading the Perl Regular Expressions document. No. No good.

Then it hit me. Why didn't I get a precursor function that would go through the data first, find all instances of links and remove them (leaving a flag for later). Then I would run the autolinks, then simply replace the data back after autolinking using the flags. I used the md5() function to quickly generate tags ... and it worked wonders.

I've actually really proud of this solution; it doesn't require me messing around too heavily with the perl regular expressions, and it works perfectly :D.

I've uploaded the function I use for autolinking; go give it a gander. You can see how crappy I script! Ha ha!

I think I'm going to start journaling more about web development on this site; or I may just get unlazy and actually do something with the 'learn' section on my website. Who knows.

Problem solved. Now to go learn about weird chemical things for my exam on Wednesday :(
Currently listening to: jimmy eat world's sweetness
Posted by roy on October 27, 2003 at 02:02 PM in Web Development | Add a comment

Related Entries

Want to comment with Tabulas?. Please login.