From: Jason Woofenden Date: Wed, 7 Sep 2011 17:19:14 +0000 (-0400) Subject: add: enc_linkify() (add tags to urls in text) X-Git-Url: https://jasonwoof.com/gitweb/?p=wfpl.git;a=commitdiff_plain;h=fa58a263a1ae73c2759648d033000a9a27f04cde add: enc_linkify() (add tags to urls in text) --- diff --git a/encode.php b/encode.php index 4ef72ae..3e9ee0c 100644 --- a/encode.php +++ b/encode.php @@ -432,3 +432,21 @@ function enc_s($str) { return 's'; } + +# 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 .= '' . enc_html($piece) . ''; + } + $even = !$even; + } + return $ret; +}