You need a regular expression to do that.

For URLs
ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=\"\\0\">\\0</a>", $text);

For email
ereg_replace("[^<>()[:space:]]+[[:alnum:]]+@[^<>[:space:]]+[[:alnum:]]", "<a href=\"mailto:\\0\">\\0</a>", $text);

The URL one needs a fully qualified string with http:// or ftp:// at the start. You can modify it to remove that requirement though.