-
Notifications
You must be signed in to change notification settings - Fork 0
/
inc_functions.php
120 lines (107 loc) · 2.37 KB
/
inc_functions.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?
function hash_password($userEmail, $password)
{
$hashed_pass = strtolower($userEmail).$password;
for ($i = 0; $i < 1000; $i++)
{
$hashed_pass = hash("SHA512", $userEmail . $password);
}
return $hashed_pass;
}
function isAssoc(array $array) {
return (bool)count(array_filter(array_keys($array), 'is_string'));
}
/**
* Expects first level of array to be number keyed, second levels associative
* Assumes keys are consistent for all sub-arrays
* @param $array {Array}
* @return string
*/
function csv_2($array)
{
if (!isAssoc($array))
{
$row_delimiter = ";";
$col_delimiter = ",";
$csv = "";
if (isset($array) && is_array($array))
{
foreach ($array[0] as $key => $value)
{
$csv .= $key . $col_delimiter;
}
$csv = substr($csv, 0, -1);
$csv .= $row_delimiter;
for ($i = 0; $i < count($array); $i++)
{
foreach ($array[$i] as $value)
{
$csv .= $value . $col_delimiter;
}
$csv = substr($csv, 0, -1);
$csv .= $row_delimiter;
}
$csv = substr($csv, 0, -1);
}
else
return "Input is not array! (" . gettype($array) . ")";
if ($csv != "")
return $csv;
else
return "Array conversion to csv string failed!";
}
else
return "Array is associative!";
}
function csv($array)
{
function breakdown($array, $level, $col_delimiter)
{
$level += 1;
$csv = "[".$level;
foreach ($array as $key => $value)
{
if (is_array($value))
$csv .= breakdown($value, $level, $col_delimiter);
else
{
$csv .= $key."=".$value.$col_delimiter;
}
}
$csv .= "]";
return $csv;
}
if (isset($array) && is_array($array))
{
$level = 0;
$row_delimiter = ";";
$col_delimiter = ",";
$csv = "";
foreach ($array as $key => $value)
{
if (is_array($value))
{
foreach ($array as $key2 => $value2)
{
$csv .= $key2 . "=" . $value2 . $col_delimiter;
}
$csv = substr($csv, 0, -1);
$csv .= $row_delimiter;
}
else
$csv .= $key . "=" . $value . $row_delimiter;
}
$csv = substr($csv, 0, -1);
return $csv;
}
return false;
}
function parse_csv($csv_string)
{
if (isset($csv_string) && strlen($csv_string) > 3)
{
return explode(";", $csv_string);
}
else
return false;
}