Advertisement
zero50x

RS Вывод предложений с заданным словом

May 11th, 2015
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.59 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
  5. <title></title>
  6. </head>
  7. <body>
  8.  
  9. <?php
  10. // <meta charset="utf-8" />
  11. error_reporting(E_ALL | E_STRICT);
  12. ini_set('display_errors', TRUE);
  13. ini_set('display_startup_errors', TRUE);
  14. header('Content-type: text/html; charset=windows-1251');
  15.  
  16. $g1 = microtime(true);
  17.  
  18. if (isset($_POST['add']) )
  19. {
  20.     echo "POST существует <br>";
  21.     $post_word = $_POST['text'];
  22.     echo "До замены: {$post_word} <br>";
  23.     $post_word = preg_replace("/\s/ism", "\s", $post_word);
  24.     echo "После замены: {$post_word} <br>";
  25. }
  26.  
  27. $url = "http://{$_SERVER['HTTP_HOST']}/p/"; // !!!!!!!!!!!!!!!!!
  28. $dir    = 'p';                              // !!!!!!!!!!!!!!!!!
  29. $files0 = array();
  30. $files1 = scandir($dir);
  31.  
  32. unset($files1[0]);
  33. unset($files1[1]);
  34.  
  35.  
  36. $result = array_merge($files0, $files1);
  37.  
  38.  
  39. //print_r($result);
  40.  
  41. $countfiles = count($files1);
  42. $numfiles = $countfiles-1;
  43. $countfiles = 5;
  44.  
  45. echo "Файлов (эл-в массива): $numfiles <br><br><br>\n\n\n";
  46.  
  47.  
  48. //$i = 0;
  49.  
  50. for ($i = 0; $i < $countfiles; $i++) {
  51. ############################# ИСХОДНЫЙ ФАЙЛ ##########################################
  52. $filename = "$dir/$result[$i]";
  53. $handle = fopen("$filename", "r");
  54. $contents = fread($handle, filesize($filename));
  55. //echo "$contents";
  56.  
  57. $match_a = '/<title>(.+?)<\/title>/ism';
  58. $run_title = preg_match_all($match_a, $contents, $i_a);
  59. echo "<b>{$i_a[1][0]}</b> <br>";
  60.  
  61. $pieces = explode(". ", $contents);
  62. $num_pieces = count($pieces);
  63.  
  64.     echo "</pre>";
  65.     //var_dump($pieces);
  66.     echo "</pre>";
  67.    
  68.     for ($z = 0; $z < $num_pieces; $z++) {
  69.         $match_b = "/$post_word/";
  70.         $run_title = preg_match_all($match_b, $pieces[$z], $i_b);
  71.         if(!empty($i_b[0][0])) {
  72.             //echo "Да i_b не пустая<br>";
  73.             $pieces[$z] = preg_replace("/$post_word/ism", "<font color=\"#FF0000\">$post_word</font>", $pieces[$z]);
  74.             echo "$pieces[$z] <br><br>";
  75.             //var_dump($i_b);
  76.         }
  77.        
  78.        
  79.         //echo "<b>{$i_b[1][0]}</b> <br>";
  80.         //echo "</pre>";
  81.         //var_dump($i_b);
  82.         //echo "</pre>";
  83.     }
  84.  
  85. fclose($handle);
  86.  
  87. $contents = null;
  88.  
  89. } //конец цикла одного файла
  90.  
  91. $g2 = microtime(true);
  92. $g3 = $g2 - $g1; // время генерации
  93. echo "\n<br>Время: ". $g3 ."<br>\n";
  94.  
  95. ?>
  96.  
  97. <form action="" method="POST">
  98.     <textarea name="text" cols="50"></textarea>
  99.     <button type="submit" name="add">Add</button>
  100. </form>
  101.  
  102. </body>
  103. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement