0

I have a input field which user enters something. Basically when user enter an url which start with http:// https// or www. i want to store it like <a href="user's words..">user's words...</a>

I'm working with php and mysql. I think replace function is for it. But when I read about it, this function only working on all string as far as I know.

For example:

input: Hi, how are you? Please check this link : http:// www.google.com and enjoy.

output should like below: Hi, how are you? Please check this link : http://www.google.com and enjoy.

hakki
  • 6,181
  • 6
  • 62
  • 106
  • What have you tried? Show some of the code. I would use `preg_replace` or something like it – putvande Sep 16 '13 at 17:46
  • 1
    related to http://stackoverflow.com/questions/1188129/replace-urls-in-text-with-html-links – NullPoiиteя Sep 16 '13 at 17:46
  • 1
    This question appears to be off-topic because it has been asked a million time before and a proper solution can be found at the Related Questions to the bottom right of this page. – Madara's Ghost Sep 16 '13 at 17:47
  • 1
    I doubt you really want to store it like that. You may want to display it like that, but storing it probably not. – PeeHaa Sep 16 '13 at 17:47

1 Answers1

0

Try this: (I don't test this code)

$output = preg_replace("#(http://|www\.)(.*) #Uis",'<a href="$1$2">$1$2</a>', $input);
Wikunia
  • 1,564
  • 1
  • 16
  • 37