...

View Full Version : Make links clickable



levani
03-26-2009, 09:39 PM
Hi

This is the php code which retrieves some data from database:


echo nl2br($wyaro) . "<br />" . nl2br($comment->extra_wyaro);

How can I make all links which startes from http:// clickable?

Thanks

Fumigator
03-27-2009, 12:11 AM
You're basically asking what is the regex to identify a URL, which has been covered at least a thousand times before. Google "php url regex" and I'm sure you'll find a regex to use. You can also search Coding Forums, as I've seen it discussed a number of times in the past.

sea4me
03-27-2009, 05:32 AM
Here, read this:

http://prajapatinilesh.wordpress.com/2007/08/08/php-make-urls-clickable-and-short-down/

levani
03-27-2009, 04:37 PM
Thanks a lot for help!!!

This code does this job perfect

https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?

PHP Example: Automatically link URL's inside text.

$text = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', '<a href="$1">$1</a>', $text);

Website: http://snipplr.com/view/2371/regex-regular-expression-to-match-a-url/



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum