<?php set_time_limit(0); # ignore_user_abort(); # fopen('flag','x'); # , @unlink('translated.txt'); # , $text = file_get_contents('martin_eden.txt'); # (martin_eden.txt) $symbols = array('!',',','.','\'','"','-',':',';','?',"\r",'(',')'); $text = str_replace($symbols, '', $text); # $text = str_replace("\n", ' ', $text); # $text_array = explode(' ',$text); # '' foreach($text_array as $val){ # if($val==''){continue;} $val = strtolower($val); if(array_key_exists($val, $words)){ # , $words[$val]++; }else{ # - $words[$val] = 1; } } ksort($words); # foreach($words as $w=>$v){ # ( 1-5) if($v<=5){ $rare_words[$w]=$v; } } $w_total = sizeof($rare_words); # $src = fopen('total.txt','w'); fwrite($src, $w_total); fclose($src); $src_trns = fopen('translated.txt','a'); # , $cnt=0; foreach($w_a as $w=>$v){ # if(!file_exists('flag')){ die(); # " - " - } /* translate.yandex GET-, lang - ( ), text - , . */ $arr = json_decode(file_get_contents('http://translate.yandex.net/api/v1/tr.json/translate?lang=en-ru&text='.$w,3), true); if($w!=$arr['text'][0]){ # , fwrite($src_trns, $w.'|'.$arr['text'][0]."\n"); # } $cnt++; # $src = fopen('current.txt','w'); # fwrite($src, $cnt); fclose($src); } fclose($src_trns); unlink('flag'); # "" - ?>
<?php @unlink('flag'); # "", ?>
<!DOCTYPE HTML> <html> <head> <!-- () --> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <!-- JQuery ( ) --> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script> <script> /* */ function refresh(){ /* */ $.post("current.txt",function(data) { current = data; }); /* #status */ $.post("total.txt",function(data) { $('#status').html(current+' / '+data); }); /* */ setTimeout(function(){ refresh(); }, 1000); } /* */ function stop(){ $.post("stop.php"); /* stop.php, */ } /* */ function start(){ $.post("handler.php"); /* handler.php, */ } $('document').ready(function(){ refresh(); /* , */ }); </script> </head> <body> <input type="button" value="Stop" onClick="stop();"> <input type="button" value="Start" onClick="start();"> <div id="status"></div> </body> </html>
Source: https://habr.com/ru/post/155675/
All Articles