<?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;
- Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
- Link type 1 - <a href="http://www.google.com">www.google.com</a> <br>link type 2 - <a href="http://www.goe3ogLEe.com">http://www.goe3ogLEe.com</a> <br>link type 3 - <a href="https://www.google.com">https://www.google.com</a> <br>link type 4
- <a href="http://google.com">http://google.com</a> <br>Link type 5 - <a href="http://www.vistaprint.com/local-search-profile.aspx?txi=15664&xnid=TopNav_Local+Search+Profile+">http://www.vistaprint.com/local-search-profile.aspx?txi=15664&xnid=TopNav_Local+Search+Profile+</a>
%28linked+item%29_Websites&xnav=TopNav <br>Link type 6 - <a href="http://drive.google.com/?">http://drive.google.com/?</a>
tab=mo&authuser=0#folders/0B7ZWeOAbtjQ1OHR1Yf343f33N2M
preferences:
332.34 ms | 407 KiB | 455 Q