[thelist] regular expressions and making links clickable

Ben Phillips ben at inchima.com
Fri Apr 19 05:54:00 CDT 2002


i have the following function:

function html_activate_links($str)
{
  $str = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'<a href="\\1">\\1</a>', $str);
  $str =
eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'\\1<a href="http://\\2">\\2</a>', $str);
  //$str =
eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})','<a
href=\"mailto:\\1\">\\1</a>', $str);
  return $str;
}

which i took from <http://www.zend.com/codex.php?id=395&single=1>. it
takes a piece of text ($str) and returns it but with the links made
clickable - ie. it wraps them in <a></a> tags.

the problem is, it includes a full stop at the end of a sentence...

you can see an example at <http://www.groupfmi.com/linkstest.fmi>

i've tried a couple of things, but i'm no regular expression expert,
even after reading chris' article on evolt,
<http://www.evolt.org/article/Regular_Expression_Basics/20/22700/index.h
tml>

can anybody help shed some light on this for me and help me escape the
drudgery of friday with a little bit of success?

benji.





More information about the thelist mailing list