0

I was wondering how I can turn a comment (such as stackoverflow.com) to a post as a URL so that when clicked, it will go straight to the website?

Thanks for your help in advance

Danieljkl
  • 21
  • 3
  • I think every comment on SO has a permlink... – filiprem Jan 21 '16 at 20:15
  • For example, my previous comment permlink was: http://stackoverflow.com/q/34931959/#comment57599610_34931959 – filiprem Jan 21 '16 at 20:15
  • I was hoping to spot URLs within a random block of text and make it clickable. For example, if I comment "Search on Google.com" I want to be able to click on Google.com and take me there. Right now "Search on Google.com" shows as just text, no URLs – Danieljkl Jan 21 '16 at 20:38

1 Answers1

0

You can pre-process your text and look for things that might be a URL. Look at this answer here: Regex to match URL.

You'd want to take your text, split it by white-space, then for each white-space-separated word, check if it's a URL. If it's a URL, then output a proper <a> tag surrounding it. If not, just output the word.

Community
  • 1
  • 1
Sherwin Yu
  • 3,180
  • 2
  • 25
  • 41