piz
07-26-2003, 01:45 PM
Hi,
I wanted to use the function from the zend code gallery (http://www.zend.com/codex.php?id=395&single=1) to generate urls in a text.
The function works great, but only if the "www." is not just after a line break.
I have no idea about using Regular Expressions, how do i change this to include a possible line break before the "www."? It has to be in the second line i think.
function html_activate_links($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;
}
Thx.
Greetz
Paul
I wanted to use the function from the zend code gallery (http://www.zend.com/codex.php?id=395&single=1) to generate urls in a text.
The function works great, but only if the "www." is not just after a line break.
I have no idea about using Regular Expressions, how do i change this to include a possible line break before the "www."? It has to be in the second line i think.
function html_activate_links($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;
}
Thx.
Greetz
Paul