Links can be quite confusing in drupal. When I started writing drupal modules, I quickly came across problems with links. The purpose of this page is help new drupal module builders to spend less time figuring links out than most of us. In drupal links are created with url() and l() functions. It is however recommended that you use l() instead of url().
Syntax
l($text, $path, $attributes = array(), $query = NULL, $fragment = NULL, $absolute = FALSE, $html = FALSE)
Parameters
$text
The text to be enclosed with the anchor tag. The link which is hyperlinked. In case of an image, you would place an <img> tag here.
$path
The link url. You can either use the entire http://www.mysite.com/node/publications address or start from you drupal installation directory. In the latter case, node/publications. If you are using aliases, don't use the full address method.
$attributes
An associative array of HTML attributes to apply to the anchor tag. In simpler words, an array of attributes such as target="_blank", etc.
$query
A query string to append to the link. All the stuff which follows the ? in a url.
$fragment
Place you anchor here starting with the # sign.
$absolute
If you absolute need an absolute address, set this to TRUE.
$html
If you link is not a text i.e it is an image, set this to true.
Some examples
When it comes to programming, nothing make life easier than a sample of code.
Linking Text
l('mylink', 'url_of_the_link');
Opening link in new page
l('mylink', 'url_of_the_link', array('target' => '_blank'));
Linking Image
l("<img src='my_image'>", 'url_of_the_link', NULL, NULL, NULL, FALSE, TRUE);
Adding query string
l('mylink', 'url_of_the_link', NULL, '?id=56', NULL, FALSE, TRUE);
Internal anchors
l('mylink', 'url_of_the_link', NULL, NULL, '#section8', FALSE, TRUE);