Hyperlinks within Commenting box
2 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: April 9, 2012 (RSS)
By 28sparks - April 6, 2012
Using the Commenting Plugin, is there a way to allow members to add hyperlinks into the commenting box? Or convert text to hyperlinks when output to the front-end pages?
Re: [sparks] Hyperlinks within Commenting box
By Jason - April 9, 2012
Hi,
You are going to need to use a custom function when outputting your comments to find urls within the string and output them.
Here is one function I found that works reasonably well.
URL : http://snippets.dzone.com/posts/show/6156
This code will only show a string as a link after it is saved and is used when outputting information.
For example:
Please note that this function will only work when a link has either http:// in front, or www. or both.
For example:
www.google.com - this will work
http://google.com - this will work
http://www.google.com - this will work
google.com - this will NOT work.
Hope this helps get you started.
You are going to need to use a custom function when outputting your comments to find urls within the string and output them.
Here is one function I found that works reasonably well.
URL : http://snippets.dzone.com/posts/show/6156
function make_clickable($text)
{
$ret = ' ' . $text;
$ret = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t<]*)#ise", "'\\1<a href=\"\\2\" >\\2</a>'", $ret);
$ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<]*)#ise", "'\\1<a href=\"http://\\2\" >\\2</a>'", $ret);
$ret = preg_replace("#(^|[\n ])([a-z0-9&\-_\.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret);
$ret = substr($ret, 1);
return($ret);
}
This code will only show a string as a link after it is saved and is used when outputting information.
For example:
<?php echo make_clickable($record['comment']); ?>
Please note that this function will only work when a link has either http:// in front, or www. or both.
For example:
www.google.com - this will work
http://google.com - this will work
http://www.google.com - this will work
google.com - this will NOT work.
Hope this helps get you started.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/