Drupal L function

Drupal provides a way build a link that uses results in a friendly path rather than the actual node ID (NID). It does this through the L function.
Avoid outputting "/node/341" at all costs!
Full description from Drupal is here http://api.drupal.org/api/drupal/includes%21common.inc/function/l/7

l($text, $path, array $options = array())

Example : simple text link

<?php
  $sText
= 'This is the text of the link';
 
$sPath = 'node/342';

  $sOutput = l($text, $path);

  // $sOutput would contain:  <a href='/truepagepath'>This is the text of the link</a>
?>

Example : text link with title attribute and additional classes

<?php
  $sText
= 'Displayed Title';
 
$sPath = 'node/342';
 
$aOptions = array (
         
'attributes' => array (
                  
'class' => array('linkClass', 'secondClass'),  //must be an array to support possible multiple classes
                  
'title' => 'Some longer more substantial title', //will appear as tooltip except on IE
                
),
       );
 
$sOutput = l($text, $path$aOptions);

  // $sOutput would contain:   <a href='/truepagepath' class='linkClass secondClass' title='Some longer more substantial title'>This is the text of the link</a>
?>

Example :Image Link with title attribute and additional classes

<?php
  $sText
= "<img src='/files/someImage.jpg' alt='Meaningful image description'/>";
 
$sPath = 'node/342';
 
$aOptions = array (
         
'attributes' => array (
                  
'class' => array('linkClass', 'secondClass'),  //must be an array to support possible multiple classes
                  
'title' => 'Some longer more substantial title', //will appear as tooltip except on IE
                
),
          
'html' => TRUE,
       );
 
$sOutput = l($text, $path$aOptions);

  // $sOutput would contain:   <a href='/truepagepath' class='linkClass secondClass' title='Some longer more substantial title'><img src='/files/someImage.jpg' alt='Meaningful image description'/></a>
?>

If you need to get the path alias for an item or a system path from a path alias use the function drupal_lookup_path
http://api.drupal.org/api/drupal/includes%21path.inc/function/drupal_loo...

<?php
//This will give you a path alias for a specific node
$sPagePathAlias = drupal_lookup_path('path', 'node/123');
// would return "/myfriendly-url"

//This will give you a drupal system path for a specific alias
$sPageSystemPath = drupal_lookup_path('source', '/myfriendly-url');
// would return "node/123"
?>

This can also be used to return taxonomy term paths or aliases and I believe it will work for views aliases too

The documentation also indicates that it can support looking up a path for a specific language too.

Another option for if you need a url for a node or term but no link wrapper would be to use the url() function.
http://api.drupal.org/api/drupal/includes%21common.inc/function/url/7

<?php
$fullUrl
= url('taxonomy/term/83'); //would get you the aliased path for term id 83

$fullUrl = url('node/24'); //would get you the aliased path for node 24
?>

There is an optional options array that can be passed to the function. (see the documentation in the link above)

Link to a file with stream wrapper

<?php
l
('link text', file_create_url('public://directory_inside_files_directory/file-name.jpg'));
?>

I was doing a bit of research into which was faster, url() or drupal_lookup_path() or drupal_get_path_alias.
I found no declared speed winner, but I did notice something interesting. Only the url() function is documented out to D8. The others seem to reached end of life in D7. So the recommended method ought to be the url() function is you don't need a fully wrapped anchor, or the l() if you do.

section: