Re: Making URL's and emails live links?
| From: | Jake Malone | Date: | Tue, 22 Apr 2003 17:25:03 +0000 |
| Subject: | Re: Making URL's and emails live links? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-144871@lists.php.net to get a copy of this message | ||
Taken from Andrew Collington's String Class (http://www.phpclasses.org/)
function convert_links($string) {
$string = eregi_replace("((f|ht)tp:\/\/[a-z0-9~#%@\&:=?\/\._-]+)", "<a
href=\"\\1\" target=\"_blank\">\\1</a>", $string); //http
$string =
eregi_replace("([[:space:]a-z0-9()\"'\[~#%@\&:=?\._-])(www.[a-z0-9~#%@\&:=?\
/\._-]+)", "\\1<a href=\"http://\\2\"
target=\"_blank\">\\2</a>", $string);
// www.
$string =
eregi_replace("([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})","<a
href=\"mailto:\\1\">\\1</a>", $string); //
mail
return $string;
}
if you want, you can take out target="_blank", but i find that generally
it's better to keep this in for links posted by users.
-jake
"Tomba" <cntraltdel@hotmail.com> wrote in message
news:20030422154541.77674.qmail@pb1.pair.com...
> I am looking for a way to make URL's and email addresses active links
> when found in block of text. I am setting up a classified ads site and
> would like to have the links generate automatically so advertizers
> could enter their text and not have to code the links.
>
> Anybody got some code already made to share or can point me in the
> right direction?
>
>