I am trying to match ALL hyperlinks, i.e:
- google.com
- www.google.com
- http://google.com
So far this piece of code, does the job pretty good:
/**
* Convert links
*/
$str = preg_replace('$(https?://[a-z0-9_./?=&#-]+)(?![^<>]*>)$i', ' <a href="$1" target="_blank">$1</a> ', $str." ");
$str = preg_replace('$(www\.[a-z0-9_./?=&#-]+)(?![^<>]*>)$i', '<a href="http://$1" target="_blank">$1</a> ', $str." ");
But I have stumbled upon two VALID links that does not work. See:
- http://www.sdu.dk/uddannelse/kandidat/cand,-d-,merc/adgang+sept,-d-,+2013/dk+og+ba+ivk+marketing+og+ba+int,-d-,+spr%C3%B8k/valgfagspakke
- http://www.financialtp.com/courses.asp?menu=1&;active=1&gclid=CJGd0JPUjL4CFSENcwodM1wAyA
Any solution that would find ALL matching links?