-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuggestion1.php
38 lines (35 loc) · 1002 Bytes
/
suggestion1.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
<?php
session_start();
$sid=$_SESSION['usr'];
$mng = new MongoDB\Driver\Manager("mongodb://localhost:27017");
$lastMes = file_get_contents('chatLog.txt');
$lastMes= preg_replace("</br>", "", $lastMes);
$arr = explode("\n",$lastMes);
for($i=0;$i<sizeof($arr)-1;$i++)
{
if(( strpos( $arr[$i], $sid ) == false ))
{
$lastMes=$arr[$i];
}
}
$lastMes= preg_replace("/[^a-zA-Z]/", "", $lastMes);
$lastMes= strtolower($lastMes);
$suggest=array();
$filter = [];
$options = ["projection" => ['_id' => 0]];
$query = new MongoDB\Driver\Query($filter, $options);
$rows = $mng->executeQuery("mark1.".$sid, $query);
$emp=array();
foreach ($rows as $row) {
$array[] = json_decode(json_encode($row), True); }
$lastMes1=$sid.$message;
$lastMes1= preg_replace("</br>", "", $lastMes1);
for($i=0;$i<sizeof($array);$i++)
{
if(implode(array_keys($array[$i]))== $lastMes)
{
$suggest[] = $array[$i][$lastMes];
}
}
echo $suggest[sizeof($suggest)-1];
?>