Advertisement
zero50x

Поиск предложений на нужное слово

Aug 7th, 2015
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.90 KB | None | 0 0
  1. error_reporting(E_ALL | E_STRICT);
  2. ini_set('display_errors', TRUE);
  3. ini_set('display_startup_errors', TRUE);
  4. header('Content-type: text/html; charset=windows-1251');
  5.  
  6. $g1 = microtime(true);
  7.  
  8. $url = "http://{$_SERVER['HTTP_HOST']}/p/"; // !!!!!!!!!!!!!!!!!
  9. $dir    = 'p';                              // !!!!!!!!!!!!!!!!!
  10. $files0 = array();
  11. $files1 = scandir($dir);
  12.  
  13. unset($files1[0]);
  14. unset($files1[1]);
  15.  
  16.  
  17. $result = array_merge($files0, $files1);
  18.  
  19.  
  20. //print_r($result);
  21.  
  22. $countfiles = count($files1);
  23. $numfiles = $countfiles-1;
  24.  
  25. echo "Файлов (эл-в массива): $numfiles <br><br><br>\n\n\n";
  26.  
  27.  
  28. //$i = 0;
  29.  
  30. $AlphPred = array();
  31. for ($i = 0; $i < 20000; $i++) {
  32.    
  33.     $filename = "$dir/$result[$i]";
  34.     $handle = fopen("$filename", "r");
  35.     $contents = fread($handle, filesize($filename));
  36.     //echo "$contents";
  37.    
  38.     ## !!! Для смены начала предложения заменить фразу "Для\sтого" !!!
  39.    $jj = preg_match_all("/\.\s{1,}Для\sтого[а-яёА-ЯЁa-zA-Z\s;:,-]{1,}\./sm", $contents, $result2);
  40.     //$jj = preg_match_all("/не\sочень-то[а-яёА-ЯЁa-zA-Z\s;:,-]{1,}\./sm", $contents, $result2);
  41.    
  42.     if(isset($result2[0][0])){
  43.         $tc = count($result2[0]);
  44.         //echo "$tc";
  45.        
  46.         for ($t = 0; $t < $tc; $t++) {
  47.             $result2[0][$t] = preg_replace('/^\.\s{1,}/ism', "", $result2[0][$t]);
  48.             $AlphPred[] = $result2[0][$t];
  49.         }
  50.        
  51.         /*
  52.         echo "<pre>";
  53.         //echo "jj = $jj";
  54.         var_dump($AlphPred);
  55.         echo "</pre>";
  56.         */
  57.     }
  58.  
  59.  
  60. }
  61. $AlphPred = array_unique($AlphPred);
  62. sort($AlphPred);
  63.  
  64. $CountAlphPred = count($AlphPred);
  65. for ($t = 0; $t < $CountAlphPred; $t++) {
  66. echo "{$AlphPred[$t]}<br>";
  67. }
  68.  
  69.  
  70. $g2 = microtime(true);
  71. $g3 = $g2 - $g1; // время генерации
  72. echo "\n<br>Время: ". $g3 ."<br>\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement