-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathholder.php
42 lines (36 loc) · 870 Bytes
/
holder.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
<?php
if (empty($_GET['kw'])) {
return '{}';
}
$kw = $_GET['kw'];
$kw = str_replace(' ', '', $kw);
echo getRecord($kw);
function getRecord($keyword, $num = 5)
{
$keywords = file_get_contents('Cinema/click.json');
if(empty($keywords)){
return '{}';
}
$keywords = str_replace(' ', '', $keywords);
$keywords = json_decode($keywords, true);
arsort($keywords);
$ret = array_keys($keywords);
$res = [];
$i = 0;
foreach ($ret as $val) {
if (mb_stristr($val, $keyword) !== false) {
array_push($res, $val);
if (++$i == $num) {
break;
}
}
}
return pretty($res, $keyword);
}
function pretty($res, $tar)
{
foreach ($res as $key => $kw) {
$res[$key] = str_replace($tar, '<b>' . $tar . '</b>', $kw);
}
return json_encode($res);
}