phenixfilms
asked on
Dynamically Generate Link From Text
I have a bodycontent form that my users can create. I want to automatically search the body content and turn
www.something.com/this./that/this/
or
www.something.com
or
http://websomething.someting.com
into a link. Help is appreciated
Nathan
www.something.com/this./that/this/
or
www.something.com
or
http://websomething.someting.com
into a link. Help is appreciated
Nathan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Assuming that $content is the content you wish to parse through, this will turn the new lines into <BR />, make email links into proper mailto links, and add http:// should the user have forgotten to do that.
$content = nl2br($content);
$str = $content;
$str = eregi_replace ("[[:alpha:]]+://www", "www",$str);
$str = ereg_replace ("[[:alpha:]]+://[^<>[:spa ce:]]+[[:a lnum:]/](\ .[a-z0-9-] {2,4})+", "<a href=\\0 target=_blank>\\0</a>", $str);
$str = ereg_replace ("www.[^<>[:space:]]+[[:al num:]/](\. [a-z0-9-]{ 2,4})+", "<a href=http://\\0 target=_blank>\\0</a>", $str);
$str = ereg_replace ("[[:alpha:]]+@[^<>[:space :]]+[[:aln um:]/](\.[ a-z0-9-]{2 ,4})+", "<a href=mailto:\\0 target=_blank>\\0</a>", $str);
$content = $str;
$content = nl2br($content);
$str = $content;
$str = eregi_replace ("[[:alpha:]]+://www", "www",$str);
$str = ereg_replace ("[[:alpha:]]+://[^<>[:spa
$str = ereg_replace ("www.[^<>[:space:]]+[[:al
$str = ereg_replace ("[[:alpha:]]+@[^<>[:space
$content = $str;
$txt = "http://www.google.com/test";
$txt = preg_replace( "/(?<!<a href=\")((http|ftp)+(s)?:\
echo $txt;
?>