Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*--------------view.php-----------------------------------*/
- <?php
- header("Content-Type: text/html; charset=utf-8");
- if(!empty($_FILES['txt']['tmp_name']) && file_exists($_FILES['txt']['tmp_name']))
- {
- $text = addslashes(file_get_contents($_FILES['txt']['tmp_name']));
- include("parcer.php");
- include("analyze.php");
- $prc = new parcer($text);
- $sts = $prc->Suggestions();
- analyze($sts);
- /*foreach($sts as $a)
- {
- print(md5($a)."\n");
- }
- print_r($sts);
- echo $text;*/
- }
- else
- {
- echo '
- <div>
- <form action="view.php" method="post" enctype="multipart/form-data">
- <p>Текст для анализа:
- <p><input type="file" name="txt" />
- <p><input type="submit" value="Отправить" />
- </form>
- </div>
- ';
- }
- ?>
- /*-----------------------------analyze.php--------------------------------------*/
- <?php
- function analyze($sentences)
- {
- include("sql.php");
- $count = 0;
- $size = count($sentences);
- foreach($sentences as $a)
- {
- $hash = md5($a);
- $res = mysqli_query($sql, "select count(*) FROM `sentences` WHERE `hash` ='$hash'") or die();
- $row = mysqli_fetch_row($res);
- if ($row[0] > 0)
- {
- $count++;
- }
- else
- {
- mysqli_query($sql, "insert into `sentences` (`hash`) value ('$hash')");
- }
- }
- echo $count." повторов, что составляет " . $count/$size*100 . "% текста.";
- }
- ?>
- /*---------------------parcer.php----------------------------------*/
- <?php
- Class parcer
- {
- var $text;
- function parcer($text='')
- {
- $text=preg_replace('#<.*?>#msi','',$text);
- $this->text=$text;
- }
- function Suggestions()
- {
- $r='';
- if($this->text)
- {
- preg_match_all('#((?:(?-i)[А-Я, A-Z]).*(?<=(?:[а-я, a-z, 0-9\)\"\\\'\s]))\.)#Uui',$this->text, $res);
- if(isset($res[0]) and is_array($res[0]))
- {
- foreach($res[0] as $a)
- if(!is_array($a))$r[]=$a;
- }
- }
- return $r;
- }
- }
- ?>
- /*-------------------------sql.php--------------------------------------------------*/
- <?php
- $sql=mysqli_connect("127.0.0.1","root","123789456","AP");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement