Forums

PHP

This topic is locked

auto hyperlink

Posted 17 Jan 2003 09:14:26
1
has voted
17 Jan 2003 09:14:26 Frank tedtofston posted:
I'm trying to get the code snippet to work. I'm new to this. My page is below can anyone offer a solution to get this to display.

<html>
<head>
<title>Auto Hyperlink</title>
</head>
<body><br>
<?php $text ="ATLANTA (Reuters) - A Georgia www.yahoo.com judge has issued a warrant for the arrest of entertainer www.google.com Bobby Brown, saying the rhythm and blues singer's performance this week at a www.php.net televised awards show violated his bond."; ?>
<?php
function make_clickable($text){

$ret = eregi_replace( "([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])", "<a href=\"\1://\2\3\" target=\"_blank\" target=\"_new\">\1://\2\3</a>", $text);

$ret = eregi_replace( "(([a-z0-9_]|\-|\.)+@([^[:space:]]*)([[:alnum:]-]))", "<a href=\"mailto:\1\" target=\"_new\">\1</a>", $ret);

return ($ret) ;

}
?>
<br>Hyperlinked text<br>
<?php echo $ret ; ?><br>
Original Text<br>
<?php echo $text; ?><br>
</body>
</html>



Edited by - frankster on 17 Jan 2003 09:14:42

Replies

Replied 17 Jan 2003 09:41:15
17 Jan 2003 09:41:15 Julio Taylor replied:
what do you want the code to do exactly?

------------------------
Julio

PHP | MySQL | UD4

ICQ: 19735247
Replied 17 Jan 2003 09:45:17
17 Jan 2003 09:45:17 Frank tedtofston replied:
I would like the $text praragraph to pass through the code and spit out something with the web addresses hyperlinked.
Thanks



Edited by - frankster on 17 Jan 2003 17:05:21
Replied 18 Jan 2003 02:25:12
18 Jan 2003 02:25:12 Frank tedtofston replied:
Here's the code for the hyperlinked text. It works out of the box.

<?php
function make_clickable($strText) {
$withHref = eregi_replace("([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])", "<a href=\"\\1://\\2\\3\" target=\"_blank\" target=\"_new\">\\1://\\2\\3</a>", $strText); $withMailto = eregi_replace("(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))", "<a href=\"mailto:\\1\" target=\"_new\">\\1</a>", $withHref); return($withMailto); }
?>
<html><title>Auto Hyperlink</title>
<body>
<?PHP
$mytext = "ATLANTA (Reuters) - A Georgia www.yahoo.com judge has issued a warrant for the arrest of entertainer www.google.com Bobby Brown, saying the rhythm and blues singer's performance this week at a www.php.net televised awards show violated his bond."; $newtext = make_clickable($mytext)?> <?php echo $newtext;?>

</body>
</html>


Replied 18 Jan 2003 19:20:58
18 Jan 2003 19:20:58 Nicholas Bennett replied:
what have you done changed from the original posted on the phpfreaks website<img src=../images/dmxzone/forum/icon_smile_question.gif border=0 align=middle>

www.phpfreaks.com/quickcode/Auto_Hyperlink_URLs_and_Emails/26.php

or could you just not get it to work?

all you need to do is...

&lt;?php
function make_clickable($text){

$ret = eregi_replace( "([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])", "&lt;a href=\"\1://\2\3\" target=\"_blank\" target=\"_new\"&gt;\1://\2\3&lt;/a&gt;", $text);

$ret = eregi_replace( "(([a-z0-9_]|\-|\.)+@([^[:space:]]*)([[:alnum:]-]))", "&lt;a href=\"mailto:\1\" target=\"_new\"&gt;\1&lt;/a&gt;", $ret);

return($ret);

}
?&gt;

&lt;?
$text = "this is my text, my website is www.yahoo.com and my email is ";

echo(make_clickable($text));
?&gt;
Replied 18 Jan 2003 19:42:23
18 Jan 2003 19:42:23 Frank tedtofston replied:
I just couldn't get it to work, i stake no claim on having come up with it.

Reply to this topic