Advertisement
zero50x

Дорг 2

Jan 14th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 29.08 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title></title>
  6. </head>
  7. <body>
  8.  
  9. <?php
  10. //error_reporting(E_ALL | E_STRICT);
  11. ini_set('display_errors', TRUE);
  12. ini_set('display_startup_errors', TRUE);
  13. header('Content-type: text/html; charset=UTF-8');
  14. // Функции
  15. /*
  16.     function SctiptNum($script_filename){
  17.         preg_match("/[a-z](.*?)\.php/ism", $script_filename, $SctiptNum);
  18.         preg_match("/[0-9]+$/ism", $SctiptNum[1], $NumArr);
  19.         $Num = $NumArr[0];
  20.         if(isset($Num) && !empty($Num)){
  21.             return $Num;
  22.         }
  23.         else{ exit('Функция SctiptNum не может определить номер файла скрипта') }
  24.     }
  25. */
  26.  
  27. // Соединение с БД
  28.     $link = mysqli_connect('localhost','mytest','qwerr','basat') or die("Error " . mysqli_error($link));
  29.     if(mysqli_connect_errno()) die('Ошибка соединения: '.mysqli_connect_error()); //или if(!$link) {..
  30.     mysqli_set_charset($link, "utf8");
  31.  
  32. // Соединение с БД для временных таблиц
  33.     $link_time_table = mysqli_connect('localhost','mytest','qwerr','door_mail') or die("Error " . mysqli_error($link_time_table));
  34.     if(mysqli_connect_errno()) die('Ошибка соединения: '.mysqli_connect_error());
  35.     mysqli_set_charset($link_time_table, "utf8");
  36.    
  37. // Время
  38.     $g1 = microtime(true);
  39. // Скрипт определяет свой собственный номер
  40.     //$result_num = SctiptNum($_SERVER['SCRIPT_FILENAME']);
  41.  
  42. // Таблица с которой работаем
  43.     $table_work = file_get_contents('table.txt');
  44.     echo "Беру данные из таблицы: $table_work<br>";
  45.     $source_table = $table_work;
  46.     $time_table1 = "time_table1";
  47.  
  48. # Первый блок с базой
  49.    #### СКОЛЬКО ФРАЗ В БАЗЕ (СКОЛЬКО СТРАНИЦ БУДЕТ СГЕНЕРИРОВАНО) ########################
  50.    
  51.     $res = mysqli_query($link," SELECT COUNT(*) FROM `".$source_table."` ");
  52.     if($res){ //если запрос успешный
  53.     while($row = mysqli_fetch_assoc($res))
  54.         {$data[] = $row;}
  55.     }
  56.     $myc = implode("", $data[0]);
  57.     echo "Всего фраз в таблице: = $myc<br>\n\n";
  58.    
  59.  
  60.    
  61.     #### БЕРЁМ ИЗ БД ФРАЗУ И URL КОНКРЕТНОГО ID ####################################################
  62.    
  63.     mysqli_query($link," LOCK TABLES `".$source_table."` WRITE ") or die (mysqli_errno($link) . ": ошибка лока " . mysqli_error($link). " ошибка лока \n");
  64.     $res = mysqli_query($link," SELECT `id`, `key`, `urls` FROM `".$source_table."`   LIMIT 1 ");
  65.     if($res) { //если запрос успешный
  66.         while($row = mysqli_fetch_assoc($res)) {
  67.             $mytxt[] = $row;
  68.         }  
  69.             //var_dump($mytxt);
  70.             $lastid = $mytxt[0]['id'];
  71.             $arttitle = $mytxt[0]['key'];
  72.            
  73.                 $pieces = explode("|", $mytxt[0]['urls']);
  74.                 //var_dump($pieces);
  75.                 $num_pieces = count($pieces);
  76.                    
  77.                     $ist = array();
  78.                     ### !!!!! ВАЖНО ЧТО БЫ 50 URL НЕ ОБРАБАТЫВАЛОСЬ вместо $num_pieces ставим 20
  79.                    for ($i6 = 0; $i6 < 20; $i6++) {
  80.                         if(strlen($pieces[$i6]) < 1){unset($pieces[$i6]);}
  81.                         else { $ist[] = $pieces[$i6]; }
  82.                     }
  83.                 sort($ist);
  84.                
  85.                 echo "<b>Запрос:</b> $arttitle<br><br>";
  86.  
  87.                 echo "<pre>";
  88.                 var_dump($ist);
  89.                 echo "</pre>";
  90.  
  91.                 echo "<br><br><br>";
  92. ### Удаляю значение
  93.    $zzapros = "DELETE FROM `".$source_table."` WHERE `id`=".$lastid." ";
  94.     mysqli_query($link," $zzapros ") or die (mysqli_errno($link) . ": ошDEL " . mysqli_error($link). "  ошDEL \n");
  95.     mysqli_query($link," UNLOCK TABLES ") or die (mysqli_errno($link) . ": ошибка анлока " . mysqli_error($link). " ошибка анлока \n");
  96.  
  97.         }
  98.        
  99. ############################ ПОГНАЛ САМ CURL #######################################################
  100.  
  101.  
  102. #######################################################################################
  103. #######################################################################################
  104.  
  105. if (isset($ist)) {
  106.     // Отладка
  107.     echo "ist существует<br>";
  108.  
  109. $maintext = "";
  110.     foreach ($ist as $url_link) { // здесь правильно
  111.         $url_link = trim($url_link);
  112.         if ($url_link) {
  113.             // echo "Fetching {$url_link}...<br/>\r\n";
  114.             $main = curl_init($url_link);
  115.             //шлем заголовки
  116.                 curl_setopt($main, CURLOPT_RETURNTRANSFER, 1);
  117.                 curl_setopt($main, CURLOPT_USERAGENT, 'Opera/9.80 (Windows NT 5.1; U; ru) Presto/2.7.62 Version/11.01');
  118.  
  119.             if ($main) {
  120.  
  121.                 // Выполняем запрос и приводим к одной кодировке
  122.                 $html = curl_exec($main);
  123.                
  124. ######################### Определение кодировки #############################################################
  125.    @$str_cp1251 = iconv('UTF-8', 'Windows-1251', $html);
  126.     $kod1 = preg_match('#.#u', $html);
  127.     $kod2 = preg_match('#.#u', $str_cp1251);
  128.     if ($kod1 == 0) { // если $kod1 равен нулю то это 1251, конверируем её
  129.         $html = iconv("WINDOWS-1251", "UTF-8", $html);
  130.     }
  131.     else { /* если $kod1 не равен нулю то это UTF-8 подробнее о кодировках тут: http://habrahabr.ru/post/107945/#comment_3411725 */ }
  132.  
  133.  
  134. $n_mass = 0;
  135. include 'stop_content_word.php';
  136.  
  137. // забираем title
  138.     $base_title = '/<title>(.*?)<\/title>/ism';
  139.     $pars_title = preg_match_all($base_title, $html, $title);
  140.     $my_title = $title[1][0];
  141.     echo "Title: <b>$my_title</b><br>";
  142.  
  143. ############### ЕСЛИ В TITLE ЕСТЬ ФРАЗА - НЕ ОБРАБАТЫВАЕМ ЭТУ СТРАНИЦУ #########################
  144. //
  145.     $count_t_word = count($title_content_word);  // количество стоп-слов в title берётся из файла stop_content_word
  146.     for ($iw = 0; $iw < $count_t_word; $iw++) {
  147.         $word=$title_content_word[$iw];
  148.         $pos = strpos($my_title, $word);
  149.         if ($pos != false){ $html=""; /* exit("В TITLE обнаружено запрещённое слово, обработка прекращена"); */}
  150.     }
  151.    
  152.  
  153. $text = $html;
  154. $nl = chr(13).chr(10);
  155.  
  156. // вначале избавимся от таблиц (пока их не берём, сэкономим время)
  157. $text = preg_replace('~<table.*?>~is', '<table>', $text);
  158. $text = preg_replace('/<table>(.*?)<\/table>/is', '', $text);
  159.  
  160. // удаление картинок
  161. $text = preg_replace('/<img(.+?)>/is', '', $text);
  162. // удаление ссылок
  163. $text = preg_replace('~<a.*?>~is', '<a>', $text);
  164. // $text = preg_replace('/<a>(.*?)<\/a>/i', '', $text); ссылки мне нужны ещё
  165. $text = preg_replace('/<a><\/a>/i', '', $text);
  166.  
  167. // удаление 2 и более пробелов
  168. $text = preg_replace("/\s{2,}/",' ',$text);
  169. $text = preg_replace('/\s</i', '<', $text);
  170. $text = preg_replace('/>\s/i', '>', $text);
  171. $text = preg_replace('/\s\s</i', '<', $text);
  172. $text = preg_replace('/>\s\s/i', '>', $text);
  173. $text = preg_replace('/\s\s\s</i', '<', $text);
  174. $text = preg_replace('/>\s\s\s/i', '>', $text);
  175. $text = preg_replace('/\n\n\n/i', '\n\n', $text);
  176.  
  177. // переносы <br>
  178. $text = preg_replace('/<br><br>/i', '</p><p>', $text);
  179. $text = preg_replace('/<br\s\/><br\s\/>/i', '</p><p>', $text);
  180. $text = preg_replace('/<br\/><br\/>/i', '</p><p>', $text);
  181.  
  182. $text = preg_replace('~<iframe.*?>~is', '<iframe>', $text);
  183. $text = preg_replace('/<iframe>(.*?)<\/iframe>/is', '', $text);
  184.  
  185. $text = preg_replace('~<b.*?>~is', '<b>', $text);
  186. $text = preg_replace('~<small.*?>~is', '<small>', $text);
  187. $text = preg_replace('~<big.*?>~is', '<big>', $text);
  188. $text = preg_replace('~<p.*?>~is', '<p>', $text);
  189. $text = preg_replace('~<br.*?>~is', '<br>', $text);
  190. $text = preg_replace('~<font.*?>~is', '<font>', $text);
  191. $text = preg_replace('~<div.*?>~is', '<div>', $text);
  192. $text = preg_replace('~<select.*?>~is', '<div>', $text);
  193. $text = preg_replace('~<span.*?>~is', '<span>', $text);
  194. $text = preg_replace('~<ul.*?>~is', '<ul>', $text);
  195. $text = preg_replace('~<h1.*?>~is', '<h1>', $text);
  196. $text = preg_replace('~<h2.*?>~is', '<h2>', $text);
  197. $text = preg_replace('~<h3.*?>~is', '<h3>', $text);
  198. $text = preg_replace('~<h4.*?>~is', '<h4>', $text);
  199. $text = preg_replace('~<h5.*?>~is', '<h5>', $text);
  200. $text = preg_replace('~<h6.*?>~is', '<h6>', $text);
  201.  
  202. // главная замена div и span на Р
  203. $text = preg_replace('/<div>/i', '<p>', $text);
  204. $text = preg_replace('/<\/div>/i', '</p>', $text);
  205.  
  206. $text = preg_replace('/<span>/i', '<p>', $text); // тест замена span на p
  207. $text = preg_replace('/<\/span>/i', '</p>', $text); // тест замена span на p
  208.  
  209. $text = preg_replace('/<font>/i', ' ', $text);
  210. $text = preg_replace('/<\/font>/i', ' ', $text);
  211.  
  212. $text = preg_replace('/<big>/i', '', $text);
  213. $text = preg_replace('/<\/big>/i', '', $text);
  214.  
  215. $text = preg_replace('/<small>/i', '', $text);
  216. $text = preg_replace('/<\/small>/i', '', $text);
  217.  
  218. $text = preg_replace('/<noindex>/i', '', $text);
  219. $text = preg_replace('/<\/noindex>/i', '', $text);
  220.  
  221.  
  222. $text = preg_replace('/<p><\/p>/i', '', $text);
  223. $text = preg_replace('/<li><\/li>/i', '', $text);
  224. $text = preg_replace('/<ul><\/ul>/i', '', $text);
  225. $text = preg_replace('/<ol><\/ol>/i', '', $text);
  226.  
  227. $text = preg_replace('/<script(.*?)>/is', '<script>', $text);
  228. $text = preg_replace('/<script>(.*?)<\/script>/is', '', $text);
  229. $text = preg_replace('/<noscript>(.*?)<\/noscript>/is', '', $text);
  230.  
  231. $text = preg_replace('/<form(.*?)>/is', '<form>', $text);
  232. $text = preg_replace('/<form>(.*?)<\/form>/is', '', $text);
  233.  
  234. $text = preg_replace('/<select(.*?)>/is', '<select>', $text);
  235. $text = preg_replace('/<select>(.*?)<\/select>/is', '', $text);
  236.  
  237. $text = preg_replace('/<nav(.*?)>/is', '<nav>', $text);
  238. $text = preg_replace('/<nav>.*?<\/nav>/is', '', $text);
  239.  
  240. $text = preg_replace('/<style(.*?)>/is', '<style>', $text);
  241. $text = preg_replace('/<style>.*?<\/style>/is', '', $text);
  242.  
  243. $text = preg_replace('/<ins(.*?)>/is', '<ins>', $text);
  244. $text = preg_replace('/<ins>(.*?)<\/ins>/is', '', $text);
  245. $text = preg_replace('/<xml>(.*?)<\/xml>/is', '', $text);
  246. //$text = preg_replace('/<strong>.*?<\/strong>/is', '', $text);
  247.  
  248. $text = preg_replace('/<input(.*?)>/is', '<input>', $text);
  249. $text = preg_replace('/<!(.*?)>/is', '', $text);
  250. $text = preg_replace('/<li(.*?)>/is', '<li>', $text);
  251. $text = preg_replace('/<link(.*?)>/is', '', $text);
  252.  
  253. // em и знаки после неё
  254. $text = preg_replace('/<em><\/em>/i', ' ', $text);
  255. $text = preg_replace('/<\/em><em>/i', ' ', $text);
  256. $text = preg_replace('/<em>/i', ' <em>', $text);
  257. $text = preg_replace('/<\/em>/i', '</em> ', $text);
  258.  
  259. // strong и знаки после неё
  260. $text = preg_replace('/<strong><\/strong>/i', ' ', $text);
  261. $text = preg_replace('/<\/strong><strong>/i', ' ', $text);
  262. $text = preg_replace('/<strong>/i', ' <strong>', $text);
  263. $text = preg_replace('/<\/strong>/i', '</strong> ', $text);
  264.  
  265. // b и знаки после неё
  266. $text = preg_replace('/<b><\/b>/i', ' ', $text);
  267. $text = preg_replace('/<\/b><b>/i', ' ', $text);
  268. $text = preg_replace('/<b>/i', ' <b>', $text);
  269. $text = preg_replace('/<\/b>/i', '</b> ', $text);
  270.  
  271. // i и знаки после неё
  272. $text = preg_replace('/<i><\/i>/i', '', $text);
  273. $text = preg_replace('/<\/i><i>/i', ' ', $text);
  274. $text = preg_replace('/<i>/i', ' <i>', $text);
  275. $text = preg_replace('/<\/i>/i', '</i> ', $text);
  276.  
  277. //$text = preg_replace('/<h3><\/h3>/i', '', $text);
  278. $text = preg_replace('/<p>&raquo;<\/p>/i', '', $text);
  279. $text = preg_replace('/<li><\/li>/i', '', $text);
  280. $text = preg_replace('/<ul><\/ul>/i', '', $text);
  281. $text = preg_replace('/<ol><\/ol>/i', '', $text);
  282. $text = preg_replace('/<p><p>/is', '<p>', $text);
  283. $text = preg_replace('/<\/p><\/p>/is', '</p>', $text);
  284. $text = preg_replace('/<hr\s\/>/i', '', $text);
  285. $text = preg_replace('/<li>&raquo;<\/li>/i', '', $text);
  286. $text = preg_replace('/–<i>«/i', '– <i>«', $text);
  287. $text = preg_replace('/–<b>«/i', '– <b>«', $text);
  288. $text = preg_replace('/–<em>«/i', '– <em>«', $text);
  289.  
  290. // не берёт H-заголовки, обернём в P
  291. $text = preg_replace('/<h1>/i', '<p><h1>', $text);
  292. $text = preg_replace('/<h2>/i', '<p><h2>', $text);
  293. $text = preg_replace('/<h3>/i', '<p><h3>', $text);
  294. $text = preg_replace('/<h4>/i', '<p><h4>', $text);
  295. $text = preg_replace('/<h5>/i', '<p><h5>', $text);
  296. $text = preg_replace('/<h6>/i', '<p><h6>', $text);
  297.  
  298. $text = preg_replace('/<\/h1>/is', '</h1></p>', $text);
  299. $text = preg_replace('/<\/h2>/is', '</h2></p>', $text);
  300. $text = preg_replace('/<\/h3>/is', '</h3></p>', $text);
  301. $text = preg_replace('/<\/h4>/is', '</h4></p>', $text);
  302. $text = preg_replace('/<\/h5>/is', '</h5></p>', $text);
  303. $text = preg_replace('/<\/h6>/is', '</h6></p>', $text);
  304.  
  305. // убираем пробелы перед знаками препинания
  306. $text = preg_replace('/\s\./i', '.', $text);
  307. $text = preg_replace('/\s,/i', ',', $text);
  308. $text = preg_replace('/\s:/i', ':', $text);
  309. $text = preg_replace('/\s;/i', ';', $text);
  310. $text = preg_replace('/\s!/i', '!', $text);
  311. $text = preg_replace('/\s\?/i', '?', $text);
  312.  
  313. // пустые теги
  314. $text = preg_replace('/<p><br\s\/>/i', '<p>', $text);
  315. $text = preg_replace('/<p><br>/i', '<p>', $text);
  316. $text = preg_replace('/<p><\/p>/is', '', $text);
  317. $text = preg_replace('/<p><p>/is', '<p>', $text);
  318. $text = preg_replace('/<p>\s<p>/is', '<p>', $text);
  319. $text = preg_replace('/<b><p>/is', '<p>', $text);
  320. $text = preg_replace('/<b><\/p>/is', '</p>', $text);
  321.  
  322. // отдельные русские слова
  323. $text = preg_replace('/Содержание:/i', '', $text);
  324. $text = preg_replace('/Глава 1./i', '', $text);
  325. $text = preg_replace('/Глава 2./i', '', $text);
  326. $text = preg_replace('/Глава 3./i', '', $text);
  327. $text = preg_replace('/Глава 4./i', '', $text);
  328. $text = preg_replace('/Глава 5./i', '', $text);
  329. $text = preg_replace('/Глава 6./i', '', $text);
  330. $text = preg_replace('/Глава 7./i', '', $text);
  331. $text = preg_replace('/Глава 8./i', '', $text);
  332. $text = preg_replace('/Глава 9./i', '', $text);
  333. $text = preg_replace('/Глава 10./i', '', $text);
  334. $text = preg_replace('/Раздел 1./i', '', $text);
  335. $text = preg_replace('/Раздел 2./i', '', $text);
  336. $text = preg_replace('/Раздел 3./i', '', $text);
  337. $text = preg_replace('/Раздел 4./i', '', $text);
  338. $text = preg_replace('/Раздел 5./i', '', $text);
  339. $text = preg_replace('/Раздел 6./i', '', $text);
  340. $text = preg_replace('/Раздел 7./i', '', $text);
  341. $text = preg_replace('/Раздел 8./i', '', $text);
  342. $text = preg_replace('/Раздел 9./i', '', $text);
  343. $text = preg_replace('/Раздел 10./i', '', $text);
  344.  
  345. // это попытка убрать заголовки без окончания
  346. $text = preg_replace('/<p><h1><p>/i', '<p>', $text);
  347. $text = preg_replace('/<p><h2><p>/i', '<p>', $text);
  348. $text = preg_replace('/<p><h3><p>/i', '<p>', $text);
  349. $text = preg_replace('/<p><h4><p>/i', '<p>', $text);
  350. $text = preg_replace('/<p><h5><p>/i', '<p>', $text);
  351. $text = preg_replace('/<p><h6><p>/i', '<p>', $text);
  352.  
  353. $text = preg_replace('/<\/p><\/h1><\/p>/i', '</p>', $text);
  354. $text = preg_replace('/<\/p><\/h2><\/p>/i', '</p>', $text);
  355. $text = preg_replace('/<\/p><\/h3><\/p>/i', '</p>', $text);
  356. $text = preg_replace('/<\/p><\/h4><\/p>/i', '</p>', $text);
  357. $text = preg_replace('/<\/p><\/h5><\/p>/i', '</p>', $text);
  358. $text = preg_replace('/\/<p><\/h6><\/p>/i', '</p>', $text);
  359. $text_clear_long = strip_tags($text);
  360. $long_text = strlen($text_clear_long);
  361.  
  362. // echo "$text<br>";
  363. echo "Длина текста без тегов всего: $long_text<br>";
  364.  
  365.  
  366. ################### РАЗДЕЛЯЕМ НА <A> ССЫЛКИ И СЧИТАЕМ КОЛИЧЕСТВО ###################
  367.  
  368. // сколько ссылок на странице
  369.     $match_a = '/<\/a>(.+?)<a>/ism';
  370.     $run_title = preg_match_all($match_a, $text, $i_a);
  371.     $count_a = count($i_a[0]); // считаем кол-во элементов массива num
  372.  
  373. // Обнуляем если самый большой кусок текста между ссылками < 300 символов
  374.     $ma = array();
  375.     for ($aid1 = 0; $aid1 < $count_a; $aid1++) {
  376.         $strlen_a = strlen(strip_tags($i_a[1][$aid1]));
  377.         $ma[] = $strlen_a;
  378.         $m_sum = array_sum($ma);
  379.     }
  380.     $Count_ma = count($ma);
  381.     if($Count_ma >0){
  382.         $max = max($ma); // выбираем самый большой элемент из массива ma
  383.         if ($max < 300){$text=""; /* exit("Самый большой текст между ссылками < 300"); */ }
  384.     }
  385.     echo "Самый большой кусрк между ссылок: $max<br>";
  386.     echo "Длина между ссылок: $m_sum<br>";
  387.  
  388. // Обнуляем если длина ссылок больше длины между ссылок
  389.     $match_a = '/<a>(.+?)<\/a>/ism';
  390.     $run_title = preg_match_all($match_a, $text, $i_a);
  391.     $count_a = count($i_a[0]); // считаем кол-во элементов массива num
  392.    
  393.     $sa = array();
  394.     for ($aid1 = 0; $aid1 < $count_a; $aid1++) {
  395.         $strlen_a = strlen(strip_tags($i_a[1][$aid1]));
  396.         $sa[] = $strlen_a;
  397.         $link_sum = array_sum($sa);
  398.     }
  399.     echo "Длина внутри ссылок: $link_sum<br>";
  400.     if ($link_sum > $m_sum){$text=""; /* exit("Длина ссылок больше длины между ссылок"); */}
  401.  
  402. # ЕСЛИ НЕСКОЛЬКО СЛОВ КОММЕНТАРИЕВ ТО ЭТО ОГЛАВЛЕНИЕ ###################
  403.    /*
  404.     $match_num = '/омментариев/is';
  405.     $run_title = preg_match_all($match_num, $text, $i_comm);
  406.     $count_comm = count($i_comm[0]);
  407.     echo "count_comm = $count_comm<br>";
  408.     if ($count_comm > 4){$text=""; exit("На этой странице больше 4 слов омментариев");}
  409.     */
  410.  
  411. ################### РАЗДЕЛЯЕМ НА <Р> ССЫЛКИ ###################
  412.  
  413. $match_num = '/<p>(.+?)<\/p>/ism';
  414. $run_title = preg_match_all($match_num, $text, $i_num);
  415. $count_num = count($i_num[0]);
  416. //var_dump($i_num);
  417. echo "Всего абзацев Р обнаружено: $count_num<br>";
  418. $only_echo = array();
  419. ################### ОБРАБОТКА <Р> В ПЕРВОМ МАССИВЕ ###################
  420.  
  421. for ($id1 = 0; $id1 < $count_num; $id1++) {
  422.    
  423.     #ZZZZZZZZZZZZZZZZZZZZZZZZ удаляю все после комментариев ZZZZZZZZZZZZZZZZZZZZZZZZ
  424.    $count_s_word = count($stop_content_word);
  425.     for ($iw = 0; $iw < $count_s_word; $iw++) {
  426.         $word=$stop_content_word[$iw];
  427.         $pos = strpos($i_num[0][$id1], $word);
  428.         if ($pos === false){/* ничего не делаем */}
  429.         else {
  430.                 for ($idp = $id1-1; $idp < $count_num; $idp++) {
  431.                     unset($i_num[0][$idp]);
  432.                 }
  433.              }
  434.     }
  435.     #ZZZZZZZZZZZZZZZZZZZZZZZZ обнуляю P со стоп-словами ZZZZZZZZZZZZZZZZZZZZZZZZ
  436.    $count_c_word = count($clean_content_word);
  437.     for ($iw = 0; $iw < $count_c_word; $iw++) {
  438.         $word=$clean_content_word[$iw];
  439.         $pos = strpos($i_num[0][$id1], $word);
  440.         if ($pos === false){// ничего не делаем
  441.             }
  442.         else{unset($i_num[0][$id1]);}
  443.     }
  444.     #ZZZZZZZZZZZZZZZZZZZZZZZZ обнуляю P с URL ZZZZZZZZZZZZZZZZZZZZZZZZ
  445.    if(preg_match('/[a-zA-Z]\.[a-zA-Z]/', $i_num[0][$id1], $matches) ){
  446.     if ($matches) {unset($i_num[0][$id1]);}
  447.     }
  448.     #ZZZZZZZZZZZZZZZZZZZZZZZZ обнуляю P с датой ZZZZZZZZZZZZZZZZZZZZZZZZ
  449.    if(preg_match('/([0-2]\d|3[01])\.(0\d|1[012])\.(\d{4})/i', $i_num[0][$id1], $matches) ){
  450.     if ($matches) {unset($i_num[0][$id1]);}
  451.     }
  452.     #ZZZZZZZZZZZZZZZZZZZZZZZZ Убираю все <b> если нет закрывающей </b> ZZZZZZZZZZZZZZZZZZZZZZZZ
  453.    $open_b = 0;
  454.     $close_b = 0;
  455.     if(preg_match('/<b>/i', $i_num[0][$id1], $matches) ){
  456.     if ($matches) {$open_b = 1; /* echo "Да ТУТ ЕСТЬ ОТКР. Б <br> open_b = $open_b<br>"; */}
  457.     }
  458.     if(preg_match('/<\/b>/i', $i_num[0][$id1], $matches) ){
  459.     if ($matches) {$close_b = 1; /* echo "Да ТУТ ЕСТЬ ЗАКР. Б <br> close_b = $close_b<br>"; */}
  460.     }
  461.     if($open_b == 1 && $close_b == 0){
  462.         $i_num[0][$id1] = preg_replace('/<b>/i', '', $i_num[0][$id1]);
  463.     }
  464.     #ZZZZZZZZZZZZZZZZZZZZZZZZ если в Р нет ни одной русской буквы удаляю ZZZZZZZZZZZZZZZZZZZZZZZZ
  465.    if(preg_match('/[а-я]/', $i_num[0][$id1], $matches4) ){
  466.     if ($matches4) {}
  467.     }else {unset($i_num[0][$id1]);}
  468.     #ZZZZZZZZZZZZZZZZZ если есть заголвок пока ничего не делаю, если нет то стираю < 200 ZZZZZZZZZZZZZZZZ
  469.    $long_id = strlen(strip_tags($i_num[0][$id1]));
  470.     if(preg_match('/<h[1-6]>/',$i_num[0][$id1],$matches) ){
  471.     if ($matches) {}
  472.     }
  473.     else {
  474.         if($long_id < 200){unset($i_num[0][$id1]);}
  475.          }
  476.  
  477.     #ZZZZZZZZZZZZZZZZZZZZZZZZ если элемент всё ещё существует - вывожу ZZZZZZZZZZZZZZZZZZZZZZZZ
  478.    if(isset($i_num[0][$id1]) && strlen(strip_tags($i_num[0][$id1])) > 0)
  479.         {
  480.             // $i_num[0][$id1] = preg_replace("/<\/h1>/is", "</h1>\n", $i_num[0][$id1]);
  481.             // $i_num[0][$id1] = preg_replace("/<\/p>/is", "</p>\n", $i_num[0][$id1]);
  482.             $i_num[0][$id1] = preg_replace('/<p>[0-9]\.\s/i', '<p>', $i_num[0][$id1]);
  483.            
  484.         // echo strlen(strip_tags($i_num[0][$id1]));
  485.         // echo "{$i_num[0][$id1]}";
  486.         $n_mass++;
  487.         $only_echo[] = $i_num[0][$id1];
  488.         }
  489.  
  490. }
  491.  
  492. // echo "<br><br><br>ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ<br><br><br>";
  493. $oe_num = count($only_echo);
  494. // Отладка
  495. echo "oe_num = $oe_num<br>";
  496. // var_dump($only_echo);
  497.  
  498. ################### ОБРАБОТКА <Р> ВО ВТОРОМ МАССИВЕ ###################
  499.  
  500.  
  501.  
  502. if($n_mass > 4){
  503.    
  504.     #TTTTTTTTTTTTTTTTTTT сначала убираем <p> вокруг заголовков TTTTTTTTTTTTTTTTTTT
  505.    for ($i = 0; $i < $oe_num; $i++) {
  506.    
  507.     // $i_num[0][$i] = preg_replace("/\n<\/p>/is", "</p>", $only_echo[$i]);
  508.    
  509.         if(preg_match('/<h[1-6]>/is',$only_echo[$i],$matches) ){
  510.             // var_dump($matches);
  511.             if ($matches) {
  512.                 echo "";
  513.                     $only_echo[$i] = preg_replace("/<p>/is", "", $only_echo[$i]);
  514.                     $only_echo[$i] = preg_replace("/<\/p>/is", "", $only_echo[$i]);
  515.                     $only_echo[$i] = preg_replace("/<h2>/is", "<h1>", $only_echo[$i]);
  516.                     $only_echo[$i] = preg_replace("/<h3>/is", "<h1>", $only_echo[$i]);
  517.                     $only_echo[$i] = preg_replace("/<h4>/is", "<h1>", $only_echo[$i]);
  518.                     $only_echo[$i] = preg_replace("/<h5>/is", "<h1>", $only_echo[$i]);
  519.                     $only_echo[$i] = preg_replace("/<h6>/is", "<h1>", $only_echo[$i]);
  520.                     $only_echo[$i] = preg_replace("/<\/h2>/is", "</h1>", $only_echo[$i]);
  521.                     $only_echo[$i] = preg_replace("/<\/h3>/is", "</h1>", $only_echo[$i]);
  522.                     $only_echo[$i] = preg_replace("/<\/h4>/is", "</h1>", $only_echo[$i]);
  523.                     $only_echo[$i] = preg_replace("/<\/h5>/is", "</h1>", $only_echo[$i]);
  524.                     $only_echo[$i] = preg_replace("/<\/h6>/is", "</h1>", $only_echo[$i]);
  525.                     $only_echo[$i] = preg_replace("/<h1>/is", "<z1><h1>", $only_echo[$i]);
  526.             }
  527.         }
  528.         else {echo "";}
  529.     // echo "{$i_num[0][$i]}";
  530.     }
  531.    
  532. // var_dump($only_echo);
  533.  
  534.     #TTTTTTTTTTTTTTTTTTT уберём предыдущий заголовок если в этом тоже есть TTTTTTTTTTTTTTTTTTT
  535.    for ($i2 = 1; $i2 < $oe_num; $i2++) {
  536.        
  537.         $i_nex = $i2+1;
  538.         $i_pred = $i2-1;
  539.         if($i_pred <= 0){$i_pred = 0;}
  540.        
  541.         //echo "{$i_num[0][$i2]}";
  542.        
  543.         if(preg_match('/<h[1-6]>/is',$only_echo[$i2],$matches) ){
  544.             // var_dump($matches);
  545.            
  546.             if ($matches)
  547.             {
  548.                 //echo "Тут есть H1-6 ";
  549.    
  550.                     if(preg_match('/<h[1-6]>/is',$only_echo[$i_pred],$matches2) ){
  551.                         // var_dump($matches);
  552.                         if ($matches2) {
  553.                             unset($only_echo[$i_pred]);
  554.                         }
  555.                     }
  556.                     else { echo "";}
  557.    
  558.                     if(!isset($only_echo[$i_nex]) ){
  559.                         //echo "Сработал isset";
  560.                         unset($only_echo[$i2]);
  561.                     }
  562.                     else { echo "";}
  563.             }
  564.         }
  565.         else {}
  566.     }
  567.  
  568.     #TTTTTTTTTTTTTTTTTTT вот это я не помню что мы делаем TTTTTTTTTTTTTTTTTTT
  569.    $only_echo[] = "<z1>";
  570.     $content = "";
  571.    
  572.     for ($i3 = 0; $i3 < $count_num; $i3++) {
  573.         $p = $count_num - 1;
  574.        
  575.         if(isset($only_echo[$i3])) {
  576.             // echo "{$only_echo[$i3]}";
  577.             $content .= "{$only_echo[$i3]}";
  578.              // if($i3 == $p) { $content .= "<z1>"; echo "ДА ПРИКРЕПИЛ Z1";}
  579.             }
  580.     }
  581.    
  582. //var_dump($only_echo);
  583.  
  584.  
  585.     #TTTTTTTTTTTTTTTTTTT объединяем блоки в элементы массива по Z1 TTTTTTTTTTTTTTTTTTT
  586.    $content .= "<z1>";
  587.    
  588.     // echo "<br><br><br><br><br><br><br><br><br><br><br>$content<br><br><br><br><br><br><br><br><br><br><br>";
  589.    
  590.     $match_z1 = '/<z1>(.+?)<z1>/ism';
  591.     $run_title = preg_match_all($match_z1, $content, $final);
  592.     $count_num = count($final[0]); // считаем кол-во элементов массива num
  593.    
  594. // var_dump($final[1]); // - это итоговый var_dump, включать смотреть только его
  595.  
  596. $f_bd = count($final[1]);
  597.  
  598.     #BBBBBBBBBBBBBBBBBBB Пишем элементы массива в БД BBBBBBBBBBBBBBBBBBBBBBB
  599.    for ($i4 = 0; $i4 < $f_bd; $i4++) {
  600.         if(isset($final[1][$i4])) {
  601.             $mytext = $final[1][$i4];
  602.             // echo "ЭТО ТЕКСТ В БАЗУ ДАННЫХ:<br> $mytext";
  603.             mysqli_query($link_time_table, "INSERT INTO `".$time_table1."` SET `text`='".$mytext."' ");
  604.             }
  605.     }
  606.     $only_echo = array();
  607.     $content = "";
  608.  
  609. // тут будет выемка из БД и запись в файл
  610.  
  611. } // конец $n_mass > 4
  612.  
  613. ############################# ЗАВЕРШАБЩИЙ БЛОК #########################
  614.  
  615.  
  616.             } else {
  617.                 echo "curl_init failure! <br/>\r\n";
  618.             }
  619.             curl_close($main);
  620.         }
  621.        
  622.     } // конец foreach
  623.    
  624. ############################# РАБОТАЕМ ПОСЛЕ foreach ТОЛЬКО С $maintext
  625. }
  626.  
  627.  
  628.  
  629.  
  630. #VVVVVVVVVVVVVVVVVVVVVVVVVV Вынимаю данные из базы для создания статьи VVVVVVVVVVVVVVVVVVVVVVVVVV
  631.    $res = mysqli_query($link_time_table," SELECT `text` FROM `".$time_table1."` ");
  632.     if($res) { //если запрос успешный
  633.         while($row = mysqli_fetch_assoc($res)) {
  634.             $mytxt[] = $row;
  635.         }  
  636.             $m_long = count($mytxt);
  637.             $gottext = "";
  638.             //echo "<br><br><br><br><br><br> А это вывод из базы mytxt <br><br><br><br><br><br><br>";
  639.             var_dump($mytxt);
  640.            
  641.             $narast_long = 0;
  642.             for ($i5 = 0; $i5 < $m_long; $i5++) {
  643.                 $gottext .= $mytxt[$i5]['text'];
  644.                 $longelement = strlen($mytxt[$i5]['text']);
  645.                 $narast_long = $narast_long + $longelement;
  646.                 echo "longelement = $longelement<br>";
  647.                 echo "narast_long = $narast_long<br>";
  648.                 if($narast_long > 20000){ break; } // ЭТО МАКСИМАЛЬНЫЙ РАЗМЕР СТАТЬИ !!
  649.                
  650.             }
  651.             //echo "<br><br><br><br><br><br> А это вывод gottext <br><br><br><br><br><br><br> $gottext";
  652.            
  653.         }
  654.        
  655. #VVVVVVVVVVVVVVVVVVVVVVVVVV Пишем элементы массива в БД VVVVVVVVVVVVVVVVVVVVVVVVVV
  656. $fname = microtime(true); //имя файла нового
  657. $file="html/$fname.html";
  658.  
  659. // вставка с дизайном
  660. include 'grabber_site_xml_list_design.php';
  661.  
  662. mysqli_query($link_time_table, " TRUNCATE `".$time_table1."` ");
  663.  
  664. $g2 = microtime(true);
  665. $g3 = $g2 - $g1; // время генерации
  666. echo "\n<br>Время регулярок: ". $g3 ."<br>\n";
  667.  
  668. ?>
  669.  
  670. <form action="" method="POST">
  671.     <textarea name="text" cols="50">http://updiet.info/kak-poxudet-v-domashnix-usloviyax.html</textarea>
  672.     <button type="submit" name="add">Add</button>
  673. </form>
  674.  
  675. </body>
  676. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement