tags:

views:

99

answers:

2

Hi,

if i stored data in DB which contains urls (for example : Go thorugh this link http://www.google.com).

when i display that data in browser, i want to display that data like " Go through this link http://www.google.com ". but that url which looks like anchor link...

if you didn't get this..open google chat...send some msg to anyone like http://google.com..if u send plain text like http://google.com,but it shows with hyper link..to that url..

i want this functionality in PHP technology...how can we implement this

thanks in advance...

+2  A: 

If I understood this correctly you want to transform URLs in a text to links automatically, without going further into details a crude (very crude) regexp should do it for now:

$textWithLinks = preg_replace('#(http|ftp)s?://[^\s]+#i', '<a href="$0">$0</a>', $textWithUrls);
thr
for reference: http://stackoverflow.com/questions/206059/php-validation-regex-for-url
Eineki
tx..for your answer.. :)
and also i have one doubt..your code is not woring with the www.google.com
because it requires the URLs to start with http, https, ftp or ftps, this can be circumvented ofc. but needs a more advanced script, I said it was *very crude*
thr
+3  A: 

So, you want to convert the urls to links in php? See the first result, or answers to same question in stackoverflow.

kkyy
+1. But you'll see people trying to answer anyway. Sob.
e-satis
+1. I'm seeing the same questions over and over again...
rogeriopvl