forked from ndmsp/connectedbooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclef.php
61 lines (51 loc) · 1.59 KB
/
clef.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
<?php
include('include/config.php');
$txt = '';
$nb = Livre::numberBook($bdd);
if($nb<50){$str = 4;}
elseif($nb<100){$str = 5;}
else{$str = 7;}
// 1. Get all the resume in a var
$array = Livre::getList($bdd);
foreach($array as $value)
{
$txt .= $value->getResume();
}
// 2. Clean the var
$txt = suppraccent($txt);
$txt = preg_replace('# #', '', $txt);
$txt = preg_replace('#, #', ' ', $txt);
// 3. Cut the variable, return an array
$txt = explode(' ', $txt);
// 4. Create a new array whitout any duplicate data
$withoutDuplicates = array_unique(array_map("strtoupper", $txt));
// 5. Create a new array whith all the duplicate data
$duplicates = array_diff($txt, $withoutDuplicates);
$duplicates = array_merge($duplicates);
$duplicates = array_map("strtolower", $duplicates);
// 6. Count how many times a same word appears
$counts = array_count_values($duplicates);
array_multisort($counts, SORT_ASC);
// 7. Delete words who come only 1 time
$i = 0;
$end = array();
foreach($counts as $key => $value){
if($value > 1 && strlen($key) > $str){
$end[] = array($i, $key, $value);
}
$i++;
}
array_multisort($end, SORT_DESC);
// 8. Save the words in the database
$i = 0;
$q = $bdd->exec('TRUNCATE TABLE mots_cles');
foreach($end as $key => $value){
if($i<15){
// echo 'Le mot <b>'.$value[1].'</b> revient <b>'.$value[2].'</b> fois !<br />';
$action = $bdd->prepare('INSERT INTO mots_cles(mot, compte) VALUES(:mot, :compte)');
$action->execute(array('mot' => $value[1], 'compte' => $value[2]));
$i++;
}
}
header('Location: admin.php?message=8');
?>