Advertisement
Golden_Rus

ap

Aug 27th, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.30 KB | None | 0 0
  1. /*--------------view.php-----------------------------------*/
  2. <?php
  3. header("Content-Type: text/html; charset=utf-8");
  4. if(!empty($_FILES['txt']['tmp_name']) && file_exists($_FILES['txt']['tmp_name']))
  5. {
  6.     $text = addslashes(file_get_contents($_FILES['txt']['tmp_name']));
  7.     include("parcer.php");
  8.     include("analyze.php");
  9.     $prc = new parcer($text);
  10.     $sts = $prc->Suggestions();
  11.     analyze($sts);
  12.     /*foreach($sts as $a)
  13.     {
  14.         print(md5($a)."\n");
  15.     }
  16.     print_r($sts);
  17.     echo $text;*/
  18. }
  19. else
  20. {
  21.     echo '
  22.   <div>
  23.   <form action="view.php" method="post" enctype="multipart/form-data">
  24.   <p>Текст для анализа:
  25.   <p><input type="file" name="txt" />
  26.   <p><input type="submit" value="Отправить" />
  27.   </form>
  28.   </div>
  29.   ';
  30. }
  31. ?>
  32.  
  33.  
  34. /*-----------------------------analyze.php--------------------------------------*/
  35. <?php
  36. function analyze($sentences)
  37. {
  38.     include("sql.php");
  39.     $count = 0;
  40.     $size = count($sentences);
  41.     foreach($sentences as $a)
  42.     {
  43.         $hash = md5($a);
  44.         $res = mysqli_query($sql, "select count(*) FROM `sentences` WHERE `hash` ='$hash'") or die();
  45.         $row = mysqli_fetch_row($res);
  46.         if ($row[0] > 0)
  47.         {
  48.             $count++;
  49.         }
  50.         else
  51.         {
  52.             mysqli_query($sql, "insert into `sentences` (`hash`) value ('$hash')");
  53.         }
  54.     }
  55.     echo $count." повторов, что составляет " . $count/$size*100 . "% текста.";
  56. }
  57. ?>
  58.  
  59. /*---------------------parcer.php----------------------------------*/
  60. <?php
  61. Class parcer
  62. {
  63.     var $text;
  64.     function parcer($text='')
  65.     {
  66.         $text=preg_replace('#<.*?>#msi','',$text);
  67.         $this->text=$text;
  68.     }
  69.     function Suggestions()
  70.     {
  71.         $r='';
  72.         if($this->text)
  73.         {
  74.             preg_match_all('#((?:(?-i)[А-Я, A-Z]).*(?<=(?:[а-я, a-z, 0-9\)\"\\\'\s]))\.)#Uui',$this->text, $res);
  75.             if(isset($res[0]) and is_array($res[0]))
  76.             {
  77.                 foreach($res[0] as $a)
  78.                 if(!is_array($a))$r[]=$a;
  79.             }
  80.         }
  81.         return $r;
  82.     }
  83. }
  84. ?>
  85.  
  86. /*-------------------------sql.php--------------------------------------------------*/
  87. <?php
  88. $sql=mysqli_connect("127.0.0.1","root","123789456","AP");
  89. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement