Жанр как тег для поиска

nexo

Пользователь
Есть задача, заносить в базу жанры фильмов, реализовано на основе мода Мета-теги (расширенная версия)
В базе таблица создана, данные заносятся, но некорректно. По аналогии с description написал для genre.
Пишутся все слова после "Жанр:" и далее ограничено количеством символов 25, а нужно сделать чтобы только до следующего слова "Страна:"

Код:
$search_word = array("Жанр");
$i= array_count_values($search_word);

if (preg_match('#Жанр#is', $text))
        {
        $pos = strpos($text, 'Жанр');
        $text_d = substr($text, $pos);
        }
    else{ $text_d = '';}
        
    if($text_d = ($text_d != '') ? $text_d : $text)
        {
        $genre = str_replace($fastquotes, '', $text_d);
        $genre = str_replace(":", '', $genre);
        $genre = preg_replace("/(\s){2,}/",' ',$genre);
        $genre = str_replace($search_word, '', trim($genre));
        $meta['genre'] = trim(bb_substr( stripslashes($genre), 0, 25, 'utf-8' ));
        
    } else { $meta['genre'] = ''; }

Полный код функции формирования мета-тегов:
Код:
Открыть includes/functions.php

В самый конец файла вставить

function meta_search ($url = false, $title = false, $images = false, $description = false, $keywords = false)
{
    global $template, $bb_cfg;
    
    $title = str_replace('"', '', $title);
    
    $description = "<meta name=\"description\" content=\"$description\" />\n";
    $keywords      = "<meta name=\"keywords\" content=\"$keywords\" />\n";
    $article      = (isset($description) || isset($keywords)) ? "<meta property=\"og:type\" content=\"article\" />\n" : "";
    $generator     = (isset($title) || isset($url) || isset($images)) ? "<meta name=\"generator\" content=\"".$bb_cfg['sitename']." (http://".$bb_cfg['server_name']."/)\" />\n" : "";
    $site_name     = (isset($title) || isset($url) || isset($images)) ? "<meta property=\"og:site_name\" content=\"".$bb_cfg['sitename']."\" />\n" : "";
    $title          = (isset($title)) ? "<meta property=\"og:title\" content=\"".strip_tags($title)."\" />\n" : "";
    $url          = (isset($url)) ? "<meta property=\"og:url\" content=\"$url\" />\n" : "";
    $images      = (isset($images)) ? "<meta property=\"og:image\" content=\"$images\" />\n" : "";
    
    $meta_tags = $description.$keywords.$generator.$site_name.$article.$title.$url.$images;
    
    $template->assign_vars(array('META_TAGS_HEAD' => $meta_tags));

}

function bb_substr($str, $start, $length, $charset ) {

    if ( strtolower($charset) == "utf-8") return iconv_substr($str, $start, $length, "utf-8");
    else return substr($str, $start, $length);

}

function bb_strlen($value, $charset ) {

    if ( strtolower($charset) == "utf-8") return iconv_strlen($value, "utf-8");
    else return strlen($value);

}

function create_metatags ($text)
{
    $keyword_count = 20;
    $newarr = array ();
    $meta['description'] = $meta['keywords'] = array();
    $quotes = array ("\x22", "\x60", "\t", '\n', '\r', "\n", "\r", '\\', ",", ".", "/", "¬", "#", ";", ":", "@", "~", "[", "]", "{", "}", "=", "-", "+", ")", "(", "*", "^", "%", "$", "<", ">", "?", "!", '"');
    $fastquotes = array ("\x22", "\x60", "\t", "\n", "\r", '"', '\r', '\n', "$", "{", "}", "[", "]", "<", ">");
    
    $text = str_replace( "&nbsp;", " ", $text);
    $text = preg_replace('#\[img=(left|right)\].*?\[/img\]\s*#isu', '', $text);
    $text = preg_replace('#\[img\].*?\[/img\]#isu', '', $text);
    $text = preg_replace('#http://.*? #isu', '', $text);
    $text = preg_replace('#\[.*?\]#isu', ' ', $text);
    $text = str_replace( '<br />', ' ', $text);
    $text = strip_tags($text);
    $text = preg_replace( "#&(.+?);#", "", $text);
    $text = trim(str_replace( " ,", "", $text));
        
    $search_word = array("Описание", "О фильме", "Сюжет фильма");
    $i= array_count_values($search_word);
    
    if (preg_match('#Описание#is', $text) || preg_match('#О фильме#is', $text) || preg_match('#Сюжет фильма#is', $text))
        {
        $pos = strpos($text, 'Сюжет фильма');
        $pos .= strpos($text, 'О фильме');
        $pos .= strpos($text, 'Описание');       
        $text_d = substr($text, $pos);
        }
    else{ $text_d = '';}
        
    if($text_d = ($text_d != '') ? $text_d : $text)
        {
        $description = str_replace($fastquotes, '', $text_d);
        $description = str_replace(":", '', $description);
        $description = preg_replace("/(\s){2,}/",' ',$description);
        $description = str_replace($search_word, '', trim($description));
        $meta['description'] = trim(bb_substr( stripslashes($description), 0, 190, 'utf-8' ));
        
    } else { $meta['description'] = ''; }
        
    if( trim($text) != "" ) {
        $text = str_replace($quotes, ' ', $text);   
        $arr = explode(" ", $text);
        
        foreach ( $arr as $word ) {
            if( bb_strlen( $word, 'utf-8' ) > 4 ) $newarr[] = $word;
        }
        
        $arr = array_count_values( $newarr );
        arsort( $arr );   
        $arr = array_keys( $arr );   
        $total = count( $arr );   
        $offset = 0;
        $arr = array_slice( $arr, $offset, $keyword_count );
        $meta['keywords'] = implode( ", ", $arr );
        
    } else { $meta['keywords'] = ''; }
    
    return $meta;
}
 
Сверху