// Multi word look up serperated by the pipe character // Format: word1 | word2 | word3 or word1|word2|word3 elseif (preg_match('#^([^|]+\s*\|\s*[^|]+(\s*\|\s*[^|]+)*)$#i', $m[1], $multi)) { // Clear any white space seperating the pipes and explode the results $words = preg_replace('#(\s+\||\|\s+)#', '', trim($multi[1])); $words = explode("|", $words); // Clean and format the words array for ($i=0;$i<<count($words);$i++) { if(substr($words[$i], 0, 1) === '(' && substr($words[$i], -1) === ')') $words[$i] = substr($words[$i], 1, -1); $words[$i] = preg_replace('#\s+#', ' ', strtolower(trim($words[$i]))); } // Clear the array of suplicate values $words = array_unique($words); // Use the multiword lookup if more than one word is given if (count($words) > 1) { // Creates the word key index used in the PDO query for($i=0;$i<count($words);$i++) $kwords[$i] = ':word'.($i+1); // Construct the PDO query $fetchMultiKarma = $this->db->prepare(' SELECT word, karma, ROWID id FROM karmas WHERE word IN ('.implode(',', $kwords).') ORDER BY karma DESC '); // Combine the words and the word key index and execute the query $res = $fetchMultiKarma->execute(array_combine($kwords, $words)); if ($res) { while (($row = $res->fetch(PDO::FETCH_ASSOC))) { $this->doPrivmsg($source, 'Debug: '.$row['word'].' => '.$row['karma']); } } } // Use the old karma fetch method if theres only one word else { $this->fetchKarma->execute(array(':word'=>$words[0])); $res = $this->fetchKarma->fetch(PDO::FETCH_ASSOC); if ($res && $res['karma'] != 0) { $this->doPrivmsg($source, $words[0].' has karma of '.$res['karma'].'.'); } else { $this->doPrivmsg($source, $words[0].' has neutral karma.'); } } }