3 * FusionForge document search engine
5 * Copyright 2005, Fabio Bertagnin
6 * Copyright 2011, Franck Villaume - Capgemini
7 * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
8 * Copyright 2012, Franck Villaume - TrivialDev
9 * http://fusionforge.org
11 * This file is part of FusionForge. FusionForge is free software;
12 * you can redistribute it and/or modify it under the terms of the
13 * GNU General Public License as published by the Free Software
14 * Foundation; either version 2 of the Licence, or (at your option)
17 * FusionForge is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 require_once $gfcommon.'include/config.php';
29 function parser_text($fichin) {
30 if (!is_file($fichin))
33 if (filesize($fichin) == 0)
36 $handle = fopen($fichin, 'r');
37 $buff = fread($handle, filesize($fichin));
40 if (function_exists('mb_strtolower')) {
41 $buff = mb_strtolower($buff);
43 $buff = strtolower($buff);
46 // élimination d'éventuels caractères unicode encore présents
47 if (function_exists('mb_convert_encoding')) {
48 $buff = mb_convert_encoding($buff, 'ascii');
51 // élimination caractères avec accents
52 // et caractères spéciaux
53 $buff = suppression_diacritics($buff);
54 // tous les mots dans un tableau
55 $words = explode(' ', $buff);
56 // élimination des doublons
57 $words = array_unique($words);
58 // envoi du résultat sur stdout
59 $rep = print_list($words);
63 function print_list($list) {
65 foreach ($list as $el) {
66 if (strlen($el) > 1) $rep .= $el.' ';
71 function suppression_diacritics($text) {
72 $text = iconv('UTF-8', 'US-ASCII//TRANSLIT', $text) ;
73 $text = strtr($text, "\t\r\n?.*'\":;,#![]()", " ");
77 function microtime_float() {
78 list($usec, $sec) = explode(" ", microtime());
79 return ((float)$usec + (float)$sec);
82 function print_debug($text) {
83 echo "$text <br />\n";
89 // c-file-style: "bsd"