+
+# turn http/ftp (s) urls into html links (and encode everything for html)
+# does not encode without protocol (eg "www.foo.com")
+# does not linkify email addresses
+function enc_linkify($str) {
+ $ret = '';
+ $even = true;
+ $pieces = preg_split("/((?:ht|f)tps?:\/\/[^ \,\"\n\r\t<]+)/is", $str, null, PREG_SPLIT_DELIM_CAPTURE);
+ foreach($pieces as $piece) {
+ if($even) {
+ $ret .= enc_html($piece);
+ } else {
+ $ret .= '<a href="' . enc_attr($piece) . '">' . enc_html($piece) . '</a>';
+ }
+ $even = !$even;
+ }
+ return $ret;
+}