I don't have much knowledge about regular expression. I found this code to detect link or you can say to insert link that is written in textarea
$url = 'this is just a link http://stackoverflow.com/ to test';
$text = preg_replace("
#((http|https|ftp)://(\S*?\.\S*?))(\s|\;|\)|\]|\[|\{|\}|,|\"|'|:|\<|$|\.\s)#ie",
"'<a href=\"$1\" target=\"_blank\">$3</a>$4'",
$url
);
echo $text;
output: this is just a link stackoverflow.com to test
But i need to separate the link into a variable from that text area. For example variable $var = http://stackoverflow.com so that i can work with the link.