X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=encode.php;h=5b8eadf9426beb13051670821f51991f8f4bf25d;hb=e3c093250e28f834151eb6ddba5ad965a8e6651b;hp=c3c71a7bb8a4613e7d27f697b564868d67b0e38e;hpb=3698f739c8155069451c61085ab925250c592e42;p=wfpl.git diff --git a/encode.php b/encode.php index c3c71a7..5b8eadf 100644 --- a/encode.php +++ b/encode.php @@ -20,8 +20,22 @@ # MA 02111-1307, USA. -# This file contains basic encodings +# This file contains basic encodings. These are used by the encoder. You can +# specify any template tag to be encoded with this syntax: ~variable.encoding~ +# +# this example:

~foo.html~

+# will encode foo (using enc_html()) before displaying it, so that characters +# such as < will display properly. + + +# encode for putting within double-quotes in SQL +function enc_sql($str) { + $str = str_replace("\\", "\\\\", $str); + $str = str_replace('"', "\\\"", $str); + return $str; +} +# encode for output in html. does nothing with whitespace function enc_html($str) { $str = str_replace('&', '&', $str); $str = str_replace('<', '<', $str); @@ -45,5 +59,20 @@ function enc_checked($str) { return ''; } } - +# add a tab at the begining of each non-empty line +function enc_tab($str) { + $lines = explode("\n", $str); + $out = ''; + foreach($lines as $line) { + if($line) { + $out .= "\t$line"; + } + $out .= "\n"; + } + + # remove the extra newline added above + return substr($out, 0, -1); +} + +?>