0

I have strings:

$string1 = 'Hi John. Please, go to my website http://www.google.com :)';
$string2 = 'See this :P www.imgurl.com/abcd.jpg';

How can I convert this strings to:

$string1 = 'Hi John. Please, go to my website <a href="http://www.google.com">http://www.google.com</a> :)';
$string2 = 'See this :P <img src="http://www.imgurl.com/abcd.jpg" alt ="" />';

I dont know ;(

Kuba Żukowski
  • 653
  • 3
  • 11
  • 16

1 Answers1

0

The best approach will be to use a regular expression to replace your URL with either the <a> Tag or the <img> Tag. The tricky part will be to determine whether it is an image or a normal URL.

Read here about PHP preg_replace function: http://de2.php.net/preg_replace

And here is a list of regular expressions to match URLs: http://regexlib.com/Search.aspx?k=url&AspxAutoDetectCookieSupport=1

Merlin Denker
  • 1,380
  • 10
  • 15