1 | <?php |
||
7 | class Strings |
||
8 | { |
||
9 | |||
10 | private $arrayUtility; |
||
11 | |||
12 | private $options = [ |
||
13 | 'stripslashes' => 1, |
||
14 | 'trim' => 1, |
||
15 | 'trimControl' => 1, |
||
16 | 'striptags' => 1, |
||
17 | ]; |
||
18 | |||
19 | public function __construct() |
||
24 | |||
25 | /** |
||
26 | * @param array $options |
||
27 | */ |
||
28 | public function setOptions($options = []) |
||
32 | |||
33 | /** |
||
34 | * @param $data |
||
35 | * @param int $length |
||
36 | * @return bool|string |
||
37 | */ |
||
38 | 2 | public function stringLength($data, $length = -1) |
|
47 | |||
48 | /** |
||
49 | * @param $string |
||
50 | * @return string |
||
51 | */ |
||
52 | 2 | public function clean($string) |
|
53 | { |
||
54 | |||
55 | 2 | $string = implode("", explode("\\", $string)); |
|
56 | |||
57 | 2 | if ($this->getOption('stripslashes') == 1) { |
|
58 | 2 | $string = stripslashes($string); |
|
59 | 2 | } |
|
60 | |||
61 | |||
62 | 2 | if ($this->getOption('trim') == 1) { |
|
63 | 2 | $string = trim($string); |
|
64 | 2 | } |
|
65 | |||
66 | 2 | if ($this->getOption('trimControl') == 1) { |
|
67 | 2 | $characters = "[[:cntrl:]]"; |
|
68 | 2 | $string = preg_replace( "/".$characters."]+/" , '' , $string ); |
|
69 | 2 | } |
|
70 | |||
71 | 2 | if ($this->getOption('striptags') == 1) { |
|
72 | 2 | $string = strip_tags($string); |
|
73 | 2 | } |
|
74 | |||
75 | 2 | return $string; |
|
76 | } |
||
77 | |||
78 | |||
79 | /** |
||
80 | * @param $name |
||
81 | * @return mixed|null |
||
82 | */ |
||
83 | 2 | private function getOption($name) |
|
91 | |||
92 | /** |
||
93 | * @param $name |
||
94 | * @return bool |
||
95 | */ |
||
96 | 2 | private function hasOption($name) |
|
100 | } |