forked from Jerglekakan/JBooru
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.global.php
68 lines (63 loc) · 1.64 KB
/
functions.global.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
<?php
function install_query($mysql_db,$table,$array,$key = '')
{
$query = 'CREATE TABLE IF NOT EXISTS '.$mysql_db.'.'.$table.'(';
$max = count($array);
$count = 0;
foreach($array as $current)
{
if($max <= 1)
$query .= $current;
else
{
if($count < ($max-1))
$query .= $current.',';
else
$query .= $current;
$count++;
}
}
if($key != '')
$query .= ',PRIMARY KEY('.$key.')';
$query .= ')';
print $query.'<br />';
$db->query($query) or print $db->error.'<br />';
foreach($array as $current)
{
$query = "ALTER TABLE $mysql_db.$table ADD COLUMN $current";
print $query.'<br />';
$db->query($query) or print $db->error.'<br />';
}
if($key != '')
{
$query = "ALTER TABLE $mysql_db.$table ADD PRIMARY KEY($key)";
print $query.'<br />';
$db->query($query) or print $db->error.'<br />';
}
}
function mb_trim($string, $charlist='\\\\s', $ltrim=true, $rtrim=true)
{
$both_ends = $ltrim && $rtrim;
$char_class_inner = preg_replace(
array( '/[\^\-\]\\\]/S', '/\\\{4}/S' ),
array( '\\\\\\0', '\\' ),
$charlist
);
$work_horse = '[' . $char_class_inner . ']+';
$ltrim && $left_pattern = '^' . $work_horse;
$rtrim && $right_pattern = $work_horse . '$';
if($both_ends)
{
$pattern_middle = $left_pattern . '|' . $right_pattern;
}
elseif($ltrim)
{
$pattern_middle = $left_pattern;
}
else
{
$pattern_middle = $right_pattern;
}
return preg_replace("/$pattern_middle/usSD", '', $string);
}
?>