If you have been doing web development for any significant amount of time chances are you know how to build a link by hand using the 'a href="link/to/some/page"' syntax. That method works fine and can even be used inside of Drupal modules, but it is generally frowned upon by the Drupal community. Using the l() function is the Drupal way of building links programmatically, and though it might take some getting used to, in the end you will find that it saves time.
l() is a function that is available anywhere within a Drupal installation. It accepts three arguments:
I will go into the t() function in a later tutorial.
I don’t know if you can see how this cleans thing up, but it really does make it easier to assemble links dynamically. Another added benefit is that links that are built using the l() function get tied into the main Drupal system and therefore are assigned active tags without you having to know anything about it. Very useful.
The $text section of the l() function accepts any text so this text could be html and therefore could be an image. However by default it filters out html unless you tell it otherwise. To tell the l() function to accept html for its text you need to build the $options array and pass it as an argument.
The 'html' =>TRUE, is the key here. Yes, I know, for building an image based link this is a little more than an ideal amount of code but this is the current state of affairs. I personally would rather have 4 arguments with $html = FALSE being the default for the third argument and $options for the 4th. This was changed in Drupal 5 where all of the options were individual arguments, and honestly the Drupal 6 version is better.
The main benefit is that the code is more compact and easier to read than manually created html. Also there is the theming benefit with the automated active classes assigned. Additionally the l() function runs check_plain and check_url in the background without you having to touch it, so it is better for security (Prevents xss attacks).
If you can find more information about the l() function by visiting its Drupal api page at http://api.drupal.org/api/function/l