Original: http://www.bbc.co.uk/radio1/photos/fearnecotton/5759/1#gallery5759
Linked: <a href="http://www.bbc.co.uk/radio1/photos/fearnecotton/5759/1#gallery5759" target="_blank">http://www.bbc.co.uk/radio1/photos/fearnecotton/5759/1#gallery5759</a>
<?php

echo "Original: "$ret 'http://www.bbc.co.uk/radio1/photos/fearnecotton/5759/1#gallery5759''<br>';

$ret preg_replace(
"#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#",
"\\1<a href=\"\\2\" target=\"_blank\">\\2</a>",
$ret
);

$ret preg_replace(
"#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#",
"\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>",
$ret
);

echo 
"Linked: "htmlentities($ret), '<hr>';

highlight_file(__FILE__);