Automatically create links from url/email

Hi there!
Does anyone have a useful php script for automatically creating links from urls or emailaddresses in a text? I found the following script:

<?php

function makeClickableLinks($text) {

  $text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
    '<a href="\\1">\\1</a>', $text);
  $text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
    '\\1<a href="http://\\2">\\2</a>', $text);
  $text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})',
    '<a href="mailto:\\1">\\1</a>', $text);
  
return $text;

}

// Usage

// Email address example
$text = "[email protected]";
echo makeClickableLinks($text);

echo "<br /><br />";

// URL example
$text = "http://www.example.com";
echo makeClickableLinks($text);

echo "<br /><br />";

// FTP URL example
$text = "ftp://ftp.example.com";
echo makeClickableLinks($text);

?>

but unfortunately, is a link starts with www. and is also the beginning of a new line of text (so there’s a <BR> begore it), it doesn’t work. Which is quite un-useful for when, for example, you want to make a list of links… I don’t ‘get’ the script well enough to edit it myself, so if anyone could give me a hand with this, er even a complete (and working!) script, I’d be really grateful!

Help?