function get_time_n_query($line) { include 'config.php'; $pos_log = strpos($line, $delimiter_for_query); $pos_log = $pos_log + strlen($delimiter_for_query); $trimmed_line = substr($line, $pos_log); $time = substr($trimmed_line, 0, strpos($trimmed_line, ' ')); //first occurence of select $query = substr($trimmed_line, strpos($trimmed_line, 'SELECT')); $query = substr($query, 0, $max_query_len); $sql_token = tokenize_query($query); $where_tokens = count_where_str_token($sql_token['where']); $assigned_grp = get_group_name($where_tokens); $hash = create_hash($sql_token['select'] . $sql_token['table'] . $assigned_grp); $response = array('group' => $assigned_grp, 'time' => $time, 'hash' => $hash, 'query' => $query, 'token' => $sql_token, 'where_tokens' => $where_tokens); return $response; }
<?php function tokenize_query($query, $punctuation) { $words = str_replace(str_split($punctuation), ' ', $query); $words = explode(' ', $words); array_walk($words, 'display'); } function display($item) { echo trim($item), "\n"; } $query = ", which isn't that surprising I guess."; tokenize_query($query, ",'.");