$re) { // Skip empty key/patterns if (!$key || !$re || strlen("$re") < 5) { continue; } // Scan through the headerPatterns defined in the schema for a match if (preg_match($re, $header)) { $this->_fieldUsed[$key] = TRUE; return $key; } } return ''; } /** * Guess at the field names given the data and patterns from the schema. * * @param array $patterns * @param string $index * * @return string */ public function defaultFromData(&$patterns, $index) { $best = ''; $bestHits = 0; $n = count($this->_dataValues); foreach ($patterns as $key => $re) { // Skip empty key/patterns if (!$key || !$re || strlen("$re") < 5) { continue; } /* Take a vote over the preview data set */ $hits = 0; for ($i = 0; $i < $n; $i++) { if (isset($this->_dataValues[$i][$index])) { if (preg_match($re, $this->_dataValues[$i][$index])) { $hits++; } } } if ($hits > $bestHits) { $bestHits = $hits; $best = $key; } } if ($best != '') { $this->_fieldUsed[$best] = TRUE; } return $best; } }