X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=encode.php;h=3e9ee0c6f5b2ec24439573fca65e01ec132b2c07;hb=cc73b808e792b3dc971d6231fc4b232f23376b93;hp=4ef72aea5bde49e26a6f01e066b1d17b0254215d;hpb=58634c046869454b074417a80cf5e35761ec9e8e;p=wfpl.git 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; +}