function number2db($value) { $larr = localeconv(); $search = array( $larr['decimal_point'], $larr['mon_decimal_point'], $larr['thousands_sep'], $larr['mon_thousands_sep'], $larr['currency_symbol'], $larr['int_curr_symbol'] ); $replace = array('.', '.', '', '', '', ''); return str_replace($search, $replace, $value); } function get_sec() { $mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; return $mtime; } /** * */ class Categorizer { static $info_tpl = array( 'matches' => array(), 'scores' => array() ); public static $info; private static $KEYWORDS = array(); private static $CATS = array(); public static function lcount( $word ) { //echo "
$string
"; //$word = iconv("cp1251", 'UTF-8', $word); //$word = preg_replace("/[^а-яА-ЯёЁa-zA-Z]/", "", trim( $word )); return strlen($word) > 2 ? array( preg_replace('/[^\w\-\d]/','', $word) => 1) : null; } public static function rcount($w1, $w2) { $w1 = !is_array($w1) ? array() : $w1; if($w2) foreach ($w2 as $word => $count) { //$word = preg_replace("/[^а-яА-ЯёЁa-zA-Z]/", "", trim( $word )); //echo "$word - !!
"; $w1[ $word ] += $count; } return $w1; } static function catParent(&$ar) { foreach($ar as $a){ if($a['Value']) return $a['Value']; } return false; } static function loadKeywords(){ $kws = array(); $mysql = mysql_query("select * from Message66 order by Category ASC"); while($tmp = mysql_fetch_assoc($mysql)) $kws[] = $tmp; self::$KEYWORDS = $kws; $cats = array(); $mysql = mysql_query("SELECT * FROM `Classificator_deal_cats` where Value < 1 "); while($tmp = mysql_fetch_assoc($mysql)) $cats[] = $tmp; self::$CATS = $cats; $res = array(); $lastcat = 0; $lastcatPid = 0; return $kws; foreach($kws as &$kw){ // if($lastcat != $kw['Category']){ // $lastcat = $kw['Category']; // $lastcatPid = self::catParent($cats); // } } } public static function execute( $text, $k = 1 ){ self::$info = self::$info_tpl; self::loadKeywords(); $tkeywords = self::$KEYWORDS; $text = preg_replace("/\d+/", "", strip_tags(strtolower($text))); $splitters = '\s.,\(\)?:;'; $array = preg_split( "/[" . $splitters . "]*\\\"([^\\\"]+)\\\"[" . $splitters . "]*|[" . $splitters . "]+/", $text, 0, PREG_SPLIT_DELIM_CAPTURE ); $array = array_map('strtolower', $array); $array = array_map('trim', $array); $array = array_map(array('Categorizer','lcount'), $array); $result = array_reduce($array, array('Categorizer','rcount')); //var_dump($result); arsort($result); $scores = array(); $scoreIndex = array(); $index = 0; $printed = array(); $loaded = array(); foreach($result as $word => $n) { $word = trim($word); foreach( self::$KEYWORDS as &$kw) { $name = $kw['Category']; $scoreIndex[$name] = ++$index; $regexp = $kw['Word']; $weight = $kw['Weight']; if( (preg_match("/^$regexp$/i", iconv("cp1251", 'utf-8', $word)) || preg_match("/^$".iconv('utf-8', "cp1251", $regexp)."$/i", $word) || preg_match("/^$regexp$/i", $word)) && !$loaded[$word.$name] ) { $loaded[$word.$name] = true; //echo "