0

I want to parse our urls and make them clickable.. even if there is not http:// in front

So for example if we have

$text = "Hello this is a sample.com so go and parse that and also http://www.sample.com"

It would make sample.com and http://www.sample.com both clickable. How would I do that with regular expressions in php?

CodeCrack
  • 5,253
  • 11
  • 44
  • 72
  • Check out this question: http://stackoverflow.com/questions/1925455/how-to-mimic-stackoverflow-auto-link-behavior – jthomas Feb 03 '13 at 03:48
  • That doesn't take care of links that don't have http:// but have .com .net at the end – CodeCrack Feb 03 '13 at 04:51
  • You can mod the regex to allow the link to also start with not only www. or http but also nothing. #\b(([\w-]+://?|www[.]|)[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))# – Victor 'Chris' Cabral Feb 03 '13 at 05:23
  • @CodeCrack without the `http://` or `www` part how would regex know that this is not a link `test.lol` ? Therefore the link provided by jthomas should help you. – HamZa Apr 21 '13 at 01:45

0 Answers0