* /*--------------------------------------------------------------------------*/ function sanitizeTags($tags='',$mode=0) { $tags = strtolower($tags); $new_tags = array(); $words = array(); $_tags = preg_split('!(\+|-|\||\s)!',$tags,-1,PREG_SPLIT_DELIM_CAPTURE); if(count($_tags)>1) { $tag = current($_tags); if(strlen($tag)>=4) $new_tags[] = $tag; next($_tags); while ($del = current($_tags)) { next($_tags); $tag = current($_tags); if(strlen($tag)>=4) { switch ( $del ) { case '+': $new_tags[] = '+'.$tag; break; case '-': $new_tags[] = '-'.$tag; break; default: $new_tags[] = $tag; break; } $words[] = $tag; } next($_tags); } } elseif(strlen($_tags[0])>=4) { $new_tags[] = $_tags[0]; $words[] = $_tags[0]; } $tags = join(chr(32),$new_tags); $query = preg_match('!(\+|-)!', $tags) ? "('+".$tags."' IN BOOLEAN MODE)": "('".$tags."')"; $query = 'WHERE MATCH (tags) AGAINST '.$query; if($mode==1) return $words; if($mode==2) return array($words,$query); return $query; } //ejemplo //$q = 'SELECT * from mitabla '.sanitizeTags('icebeat+web'); ?>