View Single Post
Old 10-26-2004, 12:23 AM   PM User | #7
greg76
New to the CF scene

 
Join Date: Oct 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
greg76 is an unknown quantity at this point
Arrow

I have similar to Firepages' solution.

PHP Code:
function addLinks($var$linkstyle){
    
$var ereg_replace("([[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/])""<a class=\"$linkstyle\" href=\"\\1\">\\1</a>"$var);
    
$var ereg_replace("([_a-zA-z0-9\-]+(\.[_a-zA-z0-9\-]+)*\@" "[_a-zA-z0-9\-]+(\.[a-zA-z]{1,3})+)""<a class=\"$linkstyle\" href=\"mailto:\\1\">\\1</a>"$var);
return 
$var

whatever you type in your cms (I am assuming you are using some cms) http://www.link.com or email@email.com, those will be turned to links.

When you want to edit text again, use this function before displaying want-to-edit data:

PHP Code:
function remLinks($var$linkstyle){
    
$var ereg_replace ("(<a class=\"$linkstyle\" href=\"[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]\">)([[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/])(</a>)","\\2"$var);
    
$var ereg_replace ("(<a class=\"$linkstyle\" href=\"mailto:)([_a-zA-z0-9\-]+(\.[_a-zA-z0-9\-]+)*\@" "[_a-zA-z0-9\-]+(\.[a-zA-z]{1,3})+)(\">)([_a-zA-z0-9\-]+(\.[_a-zA-z0-9\-]+)*\@" "[_a-zA-z0-9\-]+(\.[a-zA-z]{1,3})+</a>)""\\2",  $var);
return 
$var


I copied and modified above from my old CMS, so I hope it works properly. If not - give me a yel.

~Greg
greg76 is offline   Reply With Quote