link clickable and wordwrap

Posted by newinjs on Stack Overflow See other posts from Stack Overflow or by newinjs
Published on 2010-06-05T03:51:19Z Indexed on 2010/06/06 7:02 UTC
Read the original article Hit count: 324

Filed under:

hi,

i'm using php wordwrap for my comment box.

This is my clickable function,

function clickable_link($text)
{
$ret = ' ' . $text;
$ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a class=\"hrefLink\" href=\"\\2\" target=\"_blank\">\\2</a>", $ret);
$ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a class=\"hrefLink\" 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;
} 

and this is my wordwrap for comment

$comment = clickable_link($comment);
$comment = wordwrap($comment, 25, "\n", false);

so, once the word limit for 25 is reached, my comment box break my link

http://www.websitetitle.com/showthread.php?t=2000

link become like this

http://www.websitetitle.com/showthread.php?
<br>
t=2000

The link is broken. so is it possible to fix the link or any other workaround?

Thank you

© Stack Overflow or respective owner

Related posts about php