/
SanitizeService.php
56 lines (50 loc) · 1.45 KB
/
SanitizeService.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
49
50
51
52
53
54
55
56
<?php
/**
* Helper class for sanitizing input and escaping output.
*
* \@package Helpers
*
* @category Concrete
*
* @subpackage Security
*
* @author Chris Rosser <chris@bluefuton.com>
* @copyright Copyright (c) 2003-2008 Concrete5. (http://www.concrete5.org)
* @license http://www.concrete5.org/license/ MIT License
*/
namespace Concrete\Core\Validation;
class SanitizeService
{
/**
* Remove everything between < and > (or from < to the end of the string).
*
* @param string|mixed $string
*
* @return string|false return false if $string is not a scalar (or not an object with a __toString method), the sanitized string otherwise
*/
public function sanitizeString($string)
{
if (is_object($string) && method_exists($string, '__toString')) {
$string = (string) $string;
} elseif (is_scalar($string) || $string === null) {
$string = (string) $string;
} else {
return false;
}
$string = preg_replace('/<.*?>/ms', '', $string);
$string = preg_replace('/<.*/ms', '', $string);
return $string;
}
public function sanitizeInt($int)
{
return filter_var($int, FILTER_SANITIZE_NUMBER_INT);
}
public function sanitizeURL($url)
{
return filter_var($url, FILTER_SANITIZE_URL);
}
public function sanitizeEmail($email)
{
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
}