Posted on: 05/05/04 05:30pm
By: Anonymous (RobertM)
Posted on: 06/03/04 11:04pm
By: JohnnyWormtown
Posted on: 06/04/04 08:17pm
By: JohnnyWormtown
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<]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\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 <. $ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret); // 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 ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret); // Remove our padding.. $ret = substr($ret, 1); return($ret); } /** * Nathan Codding - Feb 6, 2001 * Reverses the effects of make_clickable(), for use in editpost. * - Does not distinguish between "www.xxxx.yyyy" and "http://aaaa.bbbb" type URLs. * */ function undo_make_clickable($text) { $text = preg_replace("#<!-- BBCode auto-link start --><a href=\"(.*?)\" target=\"_blank\">.*?</a><!-- BBCode auto-link end -->#i", "\\1", $text); $text = preg_replace("#<!-- BBcode auto-mailto start --><a href=\"mailto.*?)\">.*?</a><!-- BBCode auto-mailto end -->#i", "\\1", $text); return $text; }
Posted on: 06/05/04 02:47pm
By: JohnnyWormtown
/** * Checks for urls and eMail addresses and replaces them with links * (Stolen from phpBB and tweaked) */ 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]+?://[^ "nrt<]*)#is", "1<a href="2" target="http">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 <. $ret = preg_replace("#(^|[n ])((www|ftp).[^ "tnr<]*)#is", "1<a href="http://2" target="nohttp">2</a>", $ret); // 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 ])([a-z0-9&-_.]+?)@([w-]+.([w-.]+.)*[w]+)#i", "1<a href="mailto:2@3">2@3</a>", $ret); // Remove our padding.. $ret = substr($ret, 1); return($ret); } /** * tweaked code originally by Nathan Codding - Feb 6, 2001 * Reverses the effects of make_clickable(), for use in editpost. * - sort of distinguishes between "www.xxxx.yyyy" and "http://aaaa.bbbb" type URLs by the target set in make_clickable. * */ function undo_make_clickable($text) { $text = preg_replace("#<a href="http://(.*?)" target="nohttp">.*?</a>#i", "1", $text); $text = preg_replace("#<a href="(.*?)" target="http">.*?</a>#i", "1", $text); $text = preg_replace("#<a href="mailto.*?)">.*?</a>#i", "1", $text); return $text; }
Posted on: 06/06/04 04:24pm
By: Dirk