Hi all,

I'm having a real problem trying to create a function that can take a large string of text with some basic html markup in and find any links and then convert them to propper <a> tags.

I have found the following:

function html_activate_links_old($str) {
    $str = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '<a href="\\1" target="_blank">\\1</a>', $str);
    $str = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '\\1<a href="http://\\2" target="_blank">\\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;
}

But it falls over if the found link is already within <a> tags.

I need it to find the links NOT already linked and only activate them.

Any help would be awesome as I've reached frustration point trying to coble together loops and if statements...

TIA,

d.

    Write a Reply...