forked from surebert/surebert-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HTML.php
60 lines (54 loc) · 1.68 KB
/
HTML.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
57
58
59
60
<?php
class sb_HTML{
/**
* Recursively htmlspecialchars string properties of objects and arrays
* @param mixed $mixed The object or array to convert
* @param int $quote_style ent quote style from htmlspecialchars
* @param string $charset The charset from htmlspecialchars
* @return type
*/
public static function escape($mixed, $quote_style = ENT_QUOTES, $charset = 'UTF-8') {
if (is_string($mixed)) {
$mixed = htmlspecialchars($mixed, $quote_style, $charset);
} else if (is_object($mixed) || is_array($mixed)) {
foreach ($mixed as $k => &$v) {
if ($v) {
if (is_object($mixed)) {
$mixed->$k = self::escape($v, $quote_style, $charset);
} else {
$mixed[$k] = self::escape($v, $quote_style, $charset);
}
}
}
}
return $mixed;
}
/**
* Recursively unhtmlspecialchars string properties of objects and arrays
* @param mixed $mixed The object or array to convert
* @param int $quote_style ent quote style from htmlspecialchars
* @param string $charset The charset from htmlspecialchars
* @return type
*/
public static function unescape($mixed, $quote_style = ENT_QUOTES, $charset = 'UTF-8') {
if (is_string($mixed)) {
$mixed = str_replace('&', '&', $mixed);
$mixed = str_replace(''', '\'', $mixed);
$mixed = str_replace('"', '"', $mixed);
$mixed = str_replace('<', '<', $mixed);
$mixed = str_replace('>', '>', $mixed);
} else if (is_object($mixed) || is_array($mixed)) {
foreach ($mixed as $k => &$v) {
if ($v) {
if (is_object($mixed)) {
$mixed->$k = self::unescape($v);
} else {
$mixed[$k] = self::unescape($v);
}
}
}
}
return $mixed;
}
}
?>