-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsome_json.php
90 lines (80 loc) · 2.66 KB
/
some_json.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
<?php
include('connect/toolconnect.php');
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$sort = isset($_POST['sort']) ? strval($_POST['sort']) : 'ID';
$order = isset($_POST['order']) ? strval($_POST['order']) : 'asc';
$abstract =isset($_GET['abstract']) ? intval($_GET['abstract']) : 1;
$tables=isset($_GET['tables']) ? strval($_GET['tables']) : '';
global $Briefing_Length;//\
$Briefing_Length = 250;
$offset = ($page-1) * $rows;
$result = array();
$sql="select count(*) from " . $tables;
//echo $sql;
$rs = $mysqli->query($sql);
//echo $mysqli->error;
$row = $rs->fetch_row();
//echo $row;
$result["total"] = $row[0];
$rs1 = $mysqli->query("select * from " . $tables . " order by $sort $order limit $offset,$rows");
$items = array();
while ($row =$rs1->fetch_object()) {
// Èç¹û×Ö¶ÎÌ«³¤ Ôò¾«¼ò
// $row=strip_tags($row);
// $row=substr($row,0,50);
$row = (array)$row;
if ($abstract == 1) {
$ia = array_keys((array)$row);
for($ii = 1; $ii <= count($row); $ii++) {
if (strlen($row[$ia[$ii]]) > $Briefing_Length) {
$row[$ia[$ii]] = Generate_Brief($row[$ia[$ii]])."...";
}
}
}
array_push($items, $row);
}
$result["rows"] = $items;
echo json_encode($result);
function Generate_Brief($text) {
global $Briefing_Length;
if (strlen($text) <= $Briefing_Length) return $text;
$Foremost = substr($text, 0, $Briefing_Length);
$re = "/<(\/?)(P|DIV|H1|H2|H3|H4|H5|H6|ADDRESS|PRE|TABLE|TR|TD|TH|INPUT|SELECT|TEXTAREA|OBJECT|A|UL|OL|LI|BASE|META|LINK|HR|BR|PARAM|IMG|AREA|INPUT|SPAN)[^>]*(>?)/i";
$Single = "/BASE|META|LINK|HR|BR|PARAM|IMG|AREA|INPUT/i";
$Stack = array();
$posStack = array();
preg_match_all($re, $Foremost, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
/**
* [Child-matching Specification]:
*
* $matches[$i][1] : A "/" charactor indicating whether current "<...>" Friction is Closing Part
* $matches[$i][2] : Element Name.
* $matches[$i][3] : Right > of a "<...>" Friction
*/
for($i = 0 ; $i < count($matches); $i++) {
if ($matches[$i][1][0] == "") {
$Elem = $matches[$i][2][0];
if (preg_match($Single, $Elem) && $matches[$i][3][0] != "") {
continue;
}
array_push($Stack, strtoupper($matches[$i][2][0]));
array_push($posStack, $matches[$i][2][1]);
if ($matches[$i][3][0] == "") break;
} else {
$StackTop = $Stack[count($Stack)-1];
$End = strtoupper($matches[$i][2][0]);
if (strcasecmp($StackTop, $End) == 0) {
array_pop($Stack);
array_pop($posStack);
if ($matches[$i][3][0] == "") {
$Foremost = $Foremost . ">";
}
}
}
}
$cutpos = array_shift($posStack) - 1;
$Foremost = substr($Foremost, 0, $cutpos);
return $Foremost;
}
?>