-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.php
45 lines (39 loc) · 910 Bytes
/
helpers.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
<?php
/**
* Utility function to quickly dump data to the page
* @param null $mixed
*/
function dump($mixed = null)
{
echo '<pre>';
var_dump($mixed);
echo '</pre>';
}
/**
* Recursively escape HTML entities
* @param null $mixed
* @return array|string
*/
function sanitize($mixed = null)
{
if (!is_array($mixed)) {
return convertHtmlEntities($mixed);
}
function array_map_recursive($callback, $array)
{
$func = function ($item) use (&$func, &$callback) {
return is_array($item) ? array_map($func, $item) : call_user_func($callback, $item);
};
return array_map($func, $array);
}
return array_map_recursive('convertHtmlEntities', $mixed);
}
/**
* Escape HTML entities in the given String $str
* @param $str
* @return string
*/
function convertHtmlEntities($str)
{
return htmlentities($str, ENT_QUOTES, "UTF-8");
}