function fillSnippetsContent($template, $key_value, $conn, $page_url)
{
    $snippets_array = array();
    #scrap snippets for page
    scrapPageSnippets($snippets_array, $key_value, $conn, $page_url);
    $SNIPPET_BLOCK_1 = "<div class='wrap border-bot-1'><img src='[SNIPPET_IMG_SMALL_[INDEX]]' alt=''><p class='text-1 top-2 p3'><h2>[SNIPPET_TITLE_[INDEX]]</h2></p><p>[SNIPPET_CONTENT_[INDEX]]</p><br/></div>";
    $start_block_index = 1;
    for ($i = 1; $i <= 3; $i++) {
        if (isset($snippets_array[$i - 1])) {
            $template = preg_replace("/\\[SNIPPET_BLOCK_1_" . $start_block_index . "\\]/", preg_replace("/\\[INDEX\\]/", $i, $SNIPPET_BLOCK_1), $template);
            $start_block_index++;
        }
    }
    $SNIPPET_BLOCK_2 = "<div class='wrap'><div class='number'>[NUMBER]</div><p class='extra-wrap border-bot-1'><span class='clr-1'><h2>[SNIPPET_TITLE_[INDEX]]</h2></span><br>[SNIPPET_CONTENT_[INDEX]]</p></div>";
    $start_block_index = 1;
    for ($i = 4; $i <= 6; $i++) {
        if (isset($snippets_array[$i - 1])) {
            $template = preg_replace("/\\[SNIPPET_BLOCK_2_" . $start_block_index . "\\]/", preg_replace("/\\[INDEX\\]/", $i, preg_replace("/\\[NUMBER\\]/", $start_block_index, $SNIPPET_BLOCK_2)), $template);
            $start_block_index++;
        }
    }
    $SNIPPET_BLOCK_3 = "<div class='wrap border-bot-1'><img src='[SNIPPET_IMG_SMALL_[INDEX]]' alt='' class='img-indent'><p class='extra-wrap'><span class='clr-1'><h2>[SNIPPET_TITLE_[INDEX]]</h2></span><br>[SNIPPET_CONTENT_[INDEX]]</p></div>";
    $start_block_index = 1;
    for ($i = 7; $i <= 9; $i++) {
        if (isset($snippets_array[$i - 1])) {
            $template = preg_replace("/\\[SNIPPET_BLOCK_3_" . $start_block_index . "\\]/", preg_replace("/\\[INDEX\\]/", $i, $SNIPPET_BLOCK_3), $template);
            $start_block_index++;
        }
    }
    //clear empty blocks
    for ($i = 1; $i <= 3; $i++) {
        for ($j = 1; $j <= 3; $j++) {
            $template = preg_replace("/\\[SNIPPET_BLOCK_" . $i . "_" . $j . "\\]/", "", $template);
        }
    }
    for ($i = 0; $i < 9; $i++) {
        if (isset($snippets_array[$i])) {
            $template = preg_replace("/\\[SNIPPET_TITLE_" . ($i + 1) . "\\]/", $snippets_array[$i]["title"], $template);
            $template = preg_replace("/\\[SNIPPET_CONTENT_" . ($i + 1) . "\\]/", $snippets_array[$i]["description"], $template);
            $template = preg_replace("/\\[SNIPPET_IMG_LARGE_" . ($i + 1) . "\\]/", isset($snippets_array[$i]["large"]) ? $snippets_array[$i]["large"] : "", $template);
            $template = preg_replace("/\\[SNIPPET_IMG_SMALL_" . ($i + 1) . "\\]/", isset($snippets_array[$i]["small"]) ? $snippets_array[$i]["small"] : "", $template);
        } else {
            $template = preg_replace("/\\[SNIPPET_TITLE_" . ($i + 1) . "\\]/", "", $template);
            $template = preg_replace("/\\[SNIPPET_CONTENT_" . ($i + 1) . "\\]/", "", $template);
            $template = preg_replace("/\\[SNIPPET_IMG_LARGE_" . ($i + 1) . "\\]/", "", $template);
            $template = preg_replace("/\\[SNIPPET_IMG_SMALL_" . ($i + 1) . "\\]/", "", $template);
        }
    }
    unset($snippets_array);
    return $template;
}
if (mysqli_connect_errno())
{
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}*/
$news_count_for_posting = $news_per_day;
echo "news_count_for_posting: " . $news_count_for_posting . "<br/>";
//получаем список всех новостей, у которых время постинга больше текущего времени на 5 мин
$news_for_posting_array = getNewsIdForPostingArray($conn, $news_count_for_posting);
echo var_dump($news_for_posting_array);
$site_main_domain = $argv[1];
for ($i = 0; $i < count($news_for_posting_array); $i++) {
    postNews($conn, $news_for_posting_array[$i]);
    $key_info = getPageInfoByNewsPoster($conn, $news_for_posting_array[$i]);
    //TODO GET conn,title,keywords,description
    $page_title = $key_info['key_value'] . " | " . MAIN_TITLE;
    $page_url = $key_info['key_value_latin'];
    $keywords = $page_url;
    $description = getDescriptionByKey($page_title);
    $page_title = $page_title . " | " . $site_main_domain;
    $key_value = $key_info['key_value'];
    $snippets_array = array();
    echo "page_url: " . $page_url . "<br/>";
    echo "description: " . $description . "<br/>";
    echo "page_title: " . $page_title . "<br/>";
    echo "key_value: " . $key_value . "<br/>";
    savePageInfo($conn, $page_url, $page_title, $keywords, $description);
    //getting snippets array
    scrapPageSnippets($snippets_array, $key_value, $conn, $page_url);
}
mysqli_close($conn);
unset($conn);