X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=encode.php;h=3e9ee0c6f5b2ec24439573fca65e01ec132b2c07;hb=b714d3f571fc78989e69c7272c5812eb97479cf0;hp=7afae37c5508e304900ae035d7f241ddcf12ead2;hpb=c3cfa91f3d95f153f6c93dcff421532b9a76b1a7;p=wfpl.git diff --git a/encode.php b/encode.php index 7afae37..3e9ee0c 100644 --- a/encode.php +++ b/encode.php @@ -138,19 +138,12 @@ function enc_yesno($str) { } -# add a tab at the begining of each non-empty line +# add a tab at the begining of each line function enc_tab($str) { - $lines = explode("\n", $str); - $out = ''; - foreach($lines as $line) { - if($line) { - $out .= "\t$line"; - } - $out .= "\n"; + if('' . $str === '') { + return ''; } - - # remove the extra newline added above - return substr($out, 0, -1); + return "\t" . implode("\n\t", explode("\n", $str)); } function enc_upper($str) { @@ -439,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; +}