Question : Function to mark a link as hyper link

I need a code much like what twitter does. You submit a text. It finds the url and generates the html code which creates a hyperlink of the URL.

Answer : Function to mark a link as hyper link

There are innumerable types of URLs, but here is a basic function to get you started. Let me know if you want to add any other specific types of URLs..
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
<?php

function fun_url($s)
{
        return preg_replace("#(https?://\S*|www\.\S*|\S*\.(?:com|net|org)\S*)#", "<a href='$1'>$1</a>", $s);
}

$text = "This is a sample text contain link to google : google.com
It can also be http://yahoo.com or even www.experts-exchange.com";

echo fun_url($text);

?>
Random Solutions  
 
programming4us programming4us