JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
added enc_sql()
[wfpl.git] / encode.php
1 <?php
2
3 #  Copyright (C) 2005 Jason Woofenden
4 #
5 #  This file is part of wfpl.
6 #
7 #  wfpl is free software; you can redistribute it and/or modify it
8 #  under the terms of the GNU General Public License as published by
9 #  the Free Software Foundation; either version 2, or (at your option)
10 #  any later version.
11 #
12 #  wfpl is distributed in the hope that it will be useful, but
13 #  WITHOUT ANY WARRANTY; without even the implied warranty of
14 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 #  General Public License for more details.
16 #
17 #  You should have received a copy of the GNU General Public License
18 #  along with wfpl; see the file COPYING.  If not, write to the
19 #  Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 #  MA 02111-1307, USA.
21
22
23 # This file contains basic encodings
24
25 # encode for putting within double-quotes in SQL
26 function enc_sql($str) {
27         $str = str_replace("\\", "\\\\", $str);
28         $str = str_replace('"', "\\\"", $str);
29         return $str;
30 }
31
32 # encode for output in html. does nothing with whitespace
33 function enc_html($str) {
34         $str = str_replace('&', '&amp;', $str);
35         $str = str_replace('<', '&lt;', $str);
36         $str = str_replace('>', '&gt;', $str);
37         return $str;
38 }
39
40
41 # html attributes (eg  <input value="...."
42 function enc_attr($str) {
43         $str = str_replace('&', '&amp;', $str);
44         $str = str_replace('"', '&quot;', $str);
45         return $str;
46 }
47
48 # this is a stupid hack to work around html's stupid syntax for checkboxes
49 function enc_checked($str) {
50         if($str == 'Yes') {
51                 return '" checked="checked';
52         } else {
53                 return '';
54         }
55 }
56         
57