- str_replace: documentation ( source)
- preg_replace: documentation ( source)
<?php
$str="Link type 1 - www.google.com <br>link type 2 - http://www.goe3ogLEe.com <br>link type 3 - https://www.google.com <br>link type 4 - http://google.com <br>Link type 5 - http://www.vistaprint.com/local-search-profile.aspx?txi=15664&xnid=TopNav_Local+Search+Profile+%28linked+item%29_Websites&xnav=TopNav <br>Link type 6 - http://drive.google.com/?tab=mo&authuser=0#folders/0B7ZWeOAbtjQ1OHR1Yf343f33N2M ";
$pattern = '#(www\.|https?://)?[\w\d]+\.[\d\w]{2}\S*#i';
$str1=preg_replace($pattern, '<a href="$0">$0</a>', $str);
$str1=str_replace('href="www','href="http://www',$str1);
echo $str1;