function cat_description($info_description, $word_arr) { $descr = $info_description; $descr = str_replace("<", " <", $descr); $descr = strip_tags($descr); $descr = ereg_replace("\n", " ", $descr); $descr = ereg_replace("\r", "", $descr); $descr = ereg_replace("\t", "", $descr); $descr = ereg_replace("[[:space:]]+", " ", $descr); $info_description = ''; $max_word = 7; foreach ($word_arr as $k => $v) { $ereg_string = strlen($v) < 3 ? "(^| |[[:punct:]])" . RegExpSim(strtolower_ru($v)) . "( |[[:punct:]]|\$)" : RegExpSim(strtolower_ru($v)); if (ereg($ereg_string, strtolower_ru($info_description))) { $info_description = BoldWord($info_description, $v); continue; } if (ereg("([^ .!?]+[ ]*){0,{$max_word}}" . $ereg_string . "([ ]*[^ .!?]+){0,{$max_word}}", strtolower_ru($descr), $F)) { $pos = strpos(strtolower_ru($descr), $F[0]); $F[0] = substr($descr, $pos, strlen($F[0])); if ($pos != 0 || count($word_arr) > 1) { $info_description .= " ..."; } $info_description .= $F[0]; $info_description = BoldWord($info_description, htmlspecialchars($v, ENT_COMPAT, 'cp1251')); } } if ($info_description) { $info_description .= "..."; } return $info_description; }
function check_duble_object($word, $city_id, $object_id = 0) { $word = trim(from_form($word)); $word = ereg_replace("[[:punct:]]", " ", $word); $word_arr = split("[[:space:]]+", $word); $word_arr = array_slice($word_arr, 0, 5); $obj = $object_id ? " AND object_id!={$object_id}" : ''; $arr = array(); foreach ($word_arr as $k => $w) { if (!$k && count($word_arr) > 1) { continue; } if ($w) { $arr[] = "name regexp '[[:<:]]" . escape_string(RegExpSim($w)) . "[[:>:]]'"; } } if (count($arr)) { $s = join(" AND ", $arr); $sql = mysql_query("SELECT name FROM " . TABLE_OBJECT . " WHERE city_id={$city_id} {$obj} AND {$s}") or Error(1, __FILE__, __LINE__); //echo $s;exit; $arr = @mysql_fetch_array($sql); if (@$arr['name']) { return $arr['name']; } } return ''; }