NYCPHP Meetup

NYPHP.org

[nycphp-talk] text to link function

Jeremy Hise jhise at linuxforbusiness.org
Mon Jul 8 08:41:18 EDT 2002


Cool. I'll add it to my toolbox.

Thanks,

hise


On Sun, 2002-07-07 at 21:21, ken wu wrote:
> 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
> 
> 
> 





More information about the talk mailing list