-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfunction-library.php
48 lines (36 loc) · 1016 Bytes
/
function-library.php
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
<?php
/* formatField */
function formatField($input) {
$input = strip_tags($input);
$input = str_replace(";", ":", $input);
return trim($input);
}
/* Sanitize function */
function sanitize($dtype, $dlen, $data) {
$data = stripslashes($data);
$data = preg_replace("/x1a/",'', $data);
$data = preg_replace("/x00/",'', $data);
if($dlen != '0'){
$data = substr($data, 0, $dlen);
}
if($dtype == '1'){
// allow only numeric characters, space and '-'
$data = preg_replace("/[^0-9\-\ ]/",'', $data);
}
if($dtype == '2'){
// allow only alpha characters and space
$data = preg_replace("/[^a-zA-Z~\ ]/",'', $data);
}
if($dtype == '3'){
// allow only alphanumeric characters, space and '-'
$data = preg_replace("/[^0-9a-zA-Z~\-\ ]/",'', $data);
}
if($dtype == '4'){
// allow only alphanumeric characters w/ punctuation + carriage returns
$data = preg_replace("|[^0-9a-zA-Z~@#$%=:;_,
\\n\\\!\^&\*\(\)\-\+\.\?\/\'\"]|",' ', $data);
}
$data = addslashes($data);
return $data;
}
?>