Jeg har trimmet det oprindelige script lidt.
Min tagster-kode ser nu således ud:
function tagster_format($str, $target="_blank") {
$str = str_replace("&", "&", $str);
$str = str_replace("<", "<", $str);
$str = str_replace(">", ">", $str);
$str = tagster_url($str, $target);
$str = tagster_email($str);
$str = tagster_fix_endchar($str);
$str = str_replace(" ", " ", $str);
$str = str_replace("\t", " ", $str);
$str = str_replace("\r", "", $str);
$str = str_replace("\n", "<br><br>", $str);
return $str;
}
function tagster_url($str, $target) {
$ins_str = "";
if ($target) $ins_str .= " target=\"".$target."\"";
$str = tagster_expand($str);
$str = preg_replace ("/(ftp|http|https|telnet|news|nntp|file|irc):\/\/([a-z0-9~#%@&:;=!',_æøå\(\)\?\/\.\-\+\[\]\|\*\$\^\{\}]+)/i", "<a href=\"\\1://\\2\"".$ins_str.">\\1://\\2</a>", $str);
$str = preg_replace ("/(\s|tp\:|\(|\[|\>)(www\.)([a-z0-9~#%@&:;=!',_æøå\(\)\?\/\.\-\+\[\]\|\*\$\^\{\}]+)/i", "\\1<a href=\"
http://\\2\\3\"".$ins_str.">\\2\\3</a>", $str);
$str = preg_replace ("/(\s|tp\:|\(|\[|\>)(ftp\.)([a-z0-9~#%@&:;=!',_æøå\(\)\?\/\.\-\+\[\]\|\*\$\^\{\}]+)/i", "\\1<a href=\"
ftp://\\2\\3\"".$ins_str.">\\2\\3</a>", $str);
return tagster_reduce($str);
}
function tagster_email($str) {
$str = tagster_expand($str);
$str = preg_replace ("/([\s\"])([\w\.\-_]+)@([\w\-_]+)\.([\w\.\-_]+)/i", "\\1<a href=\"mailto:\\2@\\3.\\4\">\\2@\\3.\\4</a>", $str);
return tagster_reduce($str);
}
function tagster_fix_endchar($str) {
$str = preg_replace ("/([\'\"\)\]\.\,\?\!]+)\">/i", "\">", $str);
$str = preg_replace ("/([\'\"\)\]\.\,\?\!]+)\" (target|class)=\"/i", "\" \\2=\"", $str);
$str = preg_replace ("/([\'\"\)\]\.\,\?\!]+)<\/a>/i", "</a>\\1", $str);
return $str;
}
function tagster_expand($str) {
return " ".$str." ";
}
function tagster_reduce($str) {
return substr($str, 1, -1);
}