[Solved] Making a hyper link active
Posted: Tue Dec 26, 2006 3:15 pm
Is there any script that I can run in the head of a page that will automatically make any link in a text with http://www.thissite.com become an active link?
I have tried the script below with limited success as technically I need to run this through a loop and it’s telling me that it cannot redeclare make_clickable() previously declared si I’m puzzled as to what to do.
In essence this below is what I need to do and pick up any links such as http://www.link.com that are retrieved from the database.
Thanks
Brian
I have tried the script below with limited success as technically I need to run this through a loop and it’s telling me that it cannot redeclare make_clickable() previously declared si I’m puzzled as to what to do.
Code: Select all
<?PHP
$data = $row_GetOrchestral['OrchDetails'];
function make_clickable($text)
{
$ret = ' ' . $text;
$ret = preg_replace("#(^|[\n ])([\w]+?://[^ \"\n\r\t<]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret);
$ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\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);
}
$newdata = make_clickable($data); ?>Thanks
Brian
Code: Select all
<?php do { ?>
<strong><?php echo $row_GetOrchestral['OrchTitle']; ?></strong><br>
<?PHP
$data = $row_GetOrchestral['OrchDetails'];
function make_clickable($text)
{
$ret = ' ' . $text;
$ret = preg_replace("#(^|[\n ])([\w]+?://[^ \"\n\r\t<]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret);
$ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\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);
}
$newdata = make_clickable($data);
?> <?php echo nl2br($newdata); ?><br><br>
<?php } while ($row_GetOrchestral = mysql_fetch_assoc($GetOrchestral)); ?>