-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
153 lines (116 loc) · 3.48 KB
/
functions.php
File metadata and controls
153 lines (116 loc) · 3.48 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
/**
* Created by PhpStorm.
* User: llang
* Date: 11/27/18
* Time: 3:30 PM
*/
if (!function_exists('l')) {
function l($stuff, $suppress = FALSE)
{
$dev_log = '/var/log/dev.log';
if ($suppress) {
$stuff = var_export($stuff, TRUE) . "\n";
} else {
$stuff = timestamp() . ":\n" . var_export($stuff, TRUE) . "\n" . str_repeat('-', 30) . "\n";
}
error_log($stuff, 3, $dev_log);
}
}
// ------------------------------------------------------------------------
if (!function_exists('timestamp')) {
function timestamp()
{
return date('Y-m-d H:i:s');
}
}
// ------------------------------------------------------------------------
if (!function_exists('output')) {
function output(string $str = '', string|null $filename = ''): void
{
if ($filename) {
$filename = getcwd() . '/' . $filename;
file_put_contents($filename, $str . PHP_EOL, FILE_APPEND);
} else {
echo $str . PHP_EOL;
}
}
}
// ------------------------------------------------------------------------
if (!function_exists('dashline')) {
function dashline(int $len = 40, string|null $filename = ''): void
{
output(str_repeat('-', $len), $filename);
}
}
// ------------------------------------------------------------------------
if (!function_exists('currentDir')) {
function currentDir($filename)
{
return exec('pwd') . '/' . $filename;
}
}
// ------------------------------------------------------------------------
function array_wrap($value)
{
if (is_null($value)) {
return [];
}
return is_array($value) ? $value : [$value];
}
// ------------------------------------------------------------------------
# URL Check
function url_check($url)
{
$headers = @get_headers($url);
return is_array($headers) ? preg_match('/^HTTP\\/\\d+\\.\\d+\\s+2\\d\\d\\s+.*$/', $headers[0]) : FALSE;
}
// ------------------------------------------------------------------------
function stripRegex($str, $regex, $repl = ''): string
{
return trim(preg_replace($regex, $repl, $str));
}
// ------------------------------------------------------------------------
function stripNonAlphaNumeric($str, $repl = ''): string
{
return stripRegex($str, '/[^A-Za-z0-9]/', $repl);
}
// ------------------------------------------------------------------------
function stripNonAlphabetic($str, $repl = ''): string
{
return stripRegex($str, '/[^A-Za-z]/', $repl);
}
// ------------------------------------------------------------------------
function isEven(int $int): bool
{
return $int % 2 === 0;
}
// ------------------------------------------------------------------------
function isOdd(int $int): bool
{
return $int % 2 !== 0;
}
// ------------------------------------------------------------------------
function array_flatten(array $array): array
{
$return = [];
array_walk_recursive($array, function ($a) use (&$return) {
$return[] = $a;
});
return $return;
}
// ------------------------------------------------------------------------
function drawGrid($grid): void
{
echo PHP_EOL;
echo PHP_EOL;
for ($i = 0, $iMax = count($grid); $i < $iMax; $i++) {
for ($j = 0, $jMax = count($grid[$i]); $j < $jMax; $j++) {
echo $grid[$i][$j];
}
echo PHP_EOL;
}
echo PHP_EOL;
echo PHP_EOL;
}
// ------------------------------------------------------------------------