FilterLib.class.php

Gesponsorde koppelingen

PHP script bestanden

  1. FilterLib.class.php

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/**
 * @author Mark Eilander
 * @copyright 2010
 * @package onderzoeksinstrument
 * @version 1
 */
 
/**
 * FilterLib
 * @access public
 * @abstract
 */

abstract class FilterLib {
    
    const FILTER_WHITESPACE_ON = 1;
    const FILTER_WHITESPACE_OFF = 2;

    /**
     * strip_tags Strips all HTML tags and comments from the submitted string
     * @todo validate the optional parameter with type <p>, <b>, <style> etc
     * @static
     * @access public
     * @param string $p_sString
     * @param string $p_sParameters
     * @return Filtered string $p_sString
     */

    public static function strip_tags($p_sString, $p_sParameter = '') {
        // typecast de waarde naar een string
        $p_sString = (string) $p_sString;
        $p_sParameter = (string) $p_sParameter;
        
        // controleer of de waarde een string is en niet leeg
        if (trim($p_sString) != '') {
            // Are the optional paramets set?
            if (trim($p_sParameter) != '') {
                // Apply filter with optional parameter
                return strip_tags($p_sString, $p_sParameter);
            }
else {
                // Apply filter
                return strip_tags($p_sString);
            }
        }
else {
            $p_sString = '';
            return trim($p_sString);
        }
    }

    
    /**
     * Returns the string $value, removing all but digit characters
     * @static
     * @access public
     * @param string $p_sString
     * @return Filtered string $p_sString
     */

    public static function filter_digits($p_sString) {
        // set the pattern
         $pattern = '/[^0-9]/';
        // return the filtered string
        return preg_replace($pattern, '', (string) $p_sString);
    }

    
    /**
      * Returns the string $value, removing all but alphabetic characters
     * @static
     * @access public
     * @param string $p_sString
     * @param boolean $p_bWhitespace
     * @return Filtered string $p_sString
     */

    public static function filter_alpha($p_sString, $p_bWhitespace = self::FILTER_WHITESPACE_OFF) {
        // check whether whitespaces are allowed
        if ($p_bWhitespace === self::FILTER_WHITESPACE_ON) {
            $p_sWhitespace = '\s';
        }
else {
            $p_sWhitespace = '';
        }

        // set the pattern
         $pattern = '/[^a-zA-Z' . $p_sWhitespace . ']/';
        // return the filtered string
        return preg_replace($pattern, '', (string) $p_sString);
    }

    
    /**
      * Returns the string $value, removing all but alphabetic and digit characters
     * @static
     * @access public
     * @param string $p_sString
     * @param boolean $p_bWhitespace
     * @return Filtered string $p_sString
     */

    public static function filter_alphaNum($p_sString, $p_bWhitespace = self::FILTER_WHITESPACE_OFF) {
        // check whether whitespaces are allowed
        if ($p_bWhitespace === self::FILTER_WHITESPACE_ON) {
            $p_sWhitespace = '\s';
        }
else {
            $p_sWhitespace = '';
        }

        // set the pattern
         $pattern = '/[^a-zA-Z0-9' . $p_bWhitespace . ']/';
        // return the filtered string
        return preg_replace($pattern, '', (string) $p_sString);
    }
}

?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.