[nycphp-talk] text to link function
Anirudhsinh Zala
zala007 at hotmail.com
Mon Jul 8 09:44:13 EDT 2002
well ..
some one can try this function too :)
function gwwLinks ($data='')
{
if(empty($data)) { return $data; }
$lines = split("\
",$data);
while ( list ($key,$line) = each ($lines))
{
$line = eregi_replace("([ \ ]|^)www\\."," http://www.",$line);
$line = eregi_replace("([ \ ]|^)ftp\\."," ftp://ftp.",$line);
$line = eregi_replace("(http://[^ )\\r\
]+)","<A HREF=\\"\\\\1\\"
target=\\"_blank\\">\\\\1</A>",$line);
$line = eregi_replace("(https://[^ )\\r\
]+)","<A HREF=\\"\\\\1\\"
target=\\"_blank\\">\\\\1</A>",$line);
$line = eregi_replace("(ftp://[^ )\\r\
]+)","<A HREF=\\"\\\\1\\"
target=\\"_blank\\">\\\\1</A>",$line);
$line =
eregi_replace("([-a-z0-9_]+(\\.[_a-z0-9-]+)*@([a-z0-9-]+(\\.[a-z0-9-]+)+))","<A
HREF=\\"mailto:\\\\1\\">\\\\1</A>",$line);
$newText .= $line . "\
";
}
return $newText;
}
Thanks
Anirudhsinh
>From: ken wu <ken_11223 at yahoo.com>
>Reply-To: talk at nyphp.org
>To: NYPHP Talk <talk at nyphp.org>
>Subject: Re: [nycphp-talk] text to link function
>Date: Sun, 7 Jul 2002 21:21:43 -0400
>Received: from mc1-f26.law16.hotmail.com ([65.54.236.33]) by
>mc1-s15.law16.hotmail.com with Microsoft SMTPSVC(5.0.2195.4905); Sun, 7 Jul
>2002 18:24:55 -0700
>Received: from slipdisc.virul.net ([66.114.66.188]) by
>mc1-f26.law16.hotmail.com with Microsoft SMTPSVC(5.0.2195.4905); Sun, 7 Jul
>2002 18:24:25 -0700
>Received: from nyphp.org (slipdisc.virul.net [66.114.66.188])by
>slipdisc.virul.net (8.11.6/8.11.6) with ESMTP id g681LhP09766;Sun, 7 Jul
>2002 21:21:43 -0400 (EDT)(envelope-from listmaster at nyphp.org)
>Message-Id: <200207080121.g681LhP09766 at slipdisc.virul.net>
>X-Paralist-Archived:
><http://nyphp.org/list/paralist_archive.html?L_mid=591>
>X-List-Software: Paralist 0.6
>List-ID: <nyphptalk.nyphp.org>
>List-Owner: <mailto:listmaster at nyphp.org>
>List-Archive: <http://nyphp.org/list/paralist_archive.html?L_lid=1>
>List-Subscribe: <http://nyphp.org/list/>
>List-Unsubscribe: <http://nyphp.org/list/>
>Organization: New York PHP
>X-Mailer: Paramail 0.5
>Return-Path: listmaster at nyphp.org
>X-OriginalArrivalTime: 08 Jul 2002 01:24:25.0337 (UTC)
>FILETIME=[323A9690:01C2261E]
>
>WEll, Jeremy, though your code is good, but I think
>mine is much better. since it can as well look for
>stuff like : http://, and not XXwww.abc.com
>
>here u are :
>
>function scanText($text) { // this function is to scan
>out any URL link and return it with the ahref link
>
> $before = $text;
> //print "before = $before<br>";
> $search = array ("/(\\bhttp*:\\/\\/(\\S+)\\b)/ie",
>"/((\\s+)www(\\S+)\\b)/ie");
> $replace = array("' <a href=\\"\\\\1\\"
>target=\\"_blank\\"
>class=\\"indexMenu\\">'.trim('\\\\1').'</a> '", "' <a
>href=\\"http://'.substr(trim('\\\\1'), 0,
>strlen(trim('\\\\1'))).'\\" target=\\"_blank\\"
>class=\\"indexMenu\\">http://'.substr(trim('\\\\1'), 0,
>strlen(trim('\\\\1'))).'</a> '");
> $result = preg_replace ($search, $replace,
>$before);
>
> return "$result ";
>
>}
>
>just pass your variables through this function and get
>the link return.
>
>
>
>--- Jeremy Hise <jhise at linuxforbusiness.org> wrote:
> > Hey dude:
> >
> > The following code looks for stuff in the format of:
> >
> > www.----
> >
> > and replaces it with
> >
> > <a href = 'http://www.----'>www.-----</a>
> >
> > You can tweak it for your purposes.
> >
> > Good luck,
> >
> > Hise
> >
> > ---------------------------------
> > <?php
> > $test_text =
> > ereg_replace("www.[^<>[:space:]]+[[:alnum:]/]", "<a
> > href =
> > http://\\\\0>\\\\0</a>", $test_text);
> >
> > ?>
> > ---------------------------------
> >
> >
> >
> >
> >
> >
> > On Sun, 2002-07-07 at 04:10, Donald J. Organ IV
> > wrote:
> > > Does anyone know of any text to link functions out
> > there??
> > >
> > > to clerify what i need is i have a variable $foo
> > and i need to display any
> > > urls, if anythat are in that variable to be
> > displayed as a link.
> > >
> > > Any help would be appreciated.
> > >
> > > --Donald
> > >
> > >
> > >
> > >
> > >
> >
> >
> >
>
>
>=====
>Ken Wu
>
>718-788-0661
>168 35 Street Apt 2
>Broooklyn, NY 11232-2320
>
>http://www.kenfile.com
>
>__________________________________________________
>Do You Yahoo!?
>Sign up for SBC Yahoo! Dial - First Month Free
>http://sbc.yahoo.com
_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com
More information about the talk
mailing list