Ich hab nun was getestet, schaut schon gut aus.
Der link wird nun nach 50 Zeichen abgebrochen, und ein … wird angehängt.
Code: Alles auswählen
function make_clickable($text)
{
// pad it with a space so we can match things at the start of the 1st line.
$ret = ' ' . $text;
// matches an "xxxx://yyyy" URL at the start of a line, or after a space.
// xxxx can only be alpha characters.
// yyyy is anything up to the first space, newline, comma, double quote or <
$ret = preg_replace ("#(^|[\n ])([\w]+?://[^ \"\n\r\t<]*)#ie", "'\\1<a href=\"extern.php?\\2\" target=\"_blank\">'.urlpars('\\2').'</a>'", $ret);
// matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing
// Must contain at least 2 dots. xxxx contains either alphanum, or "-"
// zzzz is optional.. will contain everything up to the first space, newline,
// comma, double quote or <.
// matches an email@domain type address at the start of a line, or after a space.
// Note: Only the followed chars are valid; alphanums, "-", "_" and or ".".
$ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<]*)#ie", "'\\1<a href=\"extern.php?http://\\2\" target=\"_blank\">'.urlpars('\\2').'</a>'", $ret);
// Remove our padding..
$ret = substr($ret, 1);
return($ret);
}
function urlpars($tmp){
if(strlen($tmp)>= 50)
$tmp = substr($tmp, 0, 30).'...';
return($tmp);
}
Links schauen jetzt so aus:
http://www.embjapan.de/posting.php?mode=editpost&p...
was könnte mann da noch machen?