static function parseDBDate($dbDate) { $dbDate = trim($dbDate); $dbDate = str_replace(" ", ":", $dbDate); $dbDate = str_replace("-", ":", $dbDate); $dbDateArray = explode(":", $dbDate); if (count($dbDateArray) == 6) { $unixtime = mktime($dbDateArray[3], $dbDateArray[4], $dbDateArray[5], $dbDateArray[1], $dbDateArray[2], $dbDateArray[0]); return $unixtime; } if (count($dbDateArray) == 3) { $unixtime = mktime(0, 0, 0, $dbDateArray[1], $dbDateArray[2], $dbDateArray[0]); return $unixtime; } if (count($dbDateArray) == 1) { $unixtime = mktime(substr($dbDate, 8, 2), substr($dbDate, 10, 2), substr($dbDate, 12, 2), substr($dbDate, 4, 2), substr($dbDate, 6, 2), substr($dbDate, 0, 4)); return $unixtime; } FX::warn("invalid format in parseDBDate(\$dbDate={$dbDate})."); return false; }
function readArray($lines, $has_colnames = false, $has_rownames = false) { $this->clear(); $this->has_colnames = $has_colnames; $this->has_rownames = $has_rownames; $this->row_count = count($lines); if ($this->has_colnames) { $this->row_count = count($lines) - 1; } $first_line_tokens = explode($this->col_separator, $lines[0]); $this->col_count = count($first_line_tokens); if ($this->has_rownames) { $this->col_count = count($first_line_tokens) - 1; } $should_be_token_count = $this->col_count; if ($this->has_rownames) { $should_be_token_count = $this->col_count + 1; } $first_col_idx = 0; if ($this->has_rownames) { $first_col_idx = 1; } for ($i = 0; $i < count($lines); $i++) { $line = $lines[$i]; // patch Excel line breaks inside cells: --> "\t" // $line = mb_ereg_replace("\"\t\"", '|', $line); $tokens = explode($this->col_separator, $line); $tokens = FX::trimArray($tokens); // support ; inside "" ... $open = false; $newTokens = array(); for ($j = 0; $j < count($tokens); $j++) { if (strlen($tokens[$j]) > 0) { if (!$open) { if ($tokens[$j][0] == '"') { $open = true; $newToken = ""; } else { $newTokens[] = $tokens[$j]; } } if ($open) { if (strlen($newToken) > 0) { $newToken .= ";" . $tokens[$j]; } else { $newToken = $tokens[$j]; } if ($tokens[$j][strlen($tokens[$j]) - 1] == '"') { $open = false; $newTokens[] = FX::trimQuotes($newToken); } else { // no action now } } } else { $newTokens[] = $tokens[$j]; // empty token } } $tokens = $newTokens; if ($i == 0 and $this->has_colnames) { if ($this->has_rownames) { $this->title = FX::trimQuotes($tokens[0]); } //Erste Zeile mit Spaltennamen for ($j = $first_col_idx; $j < count($tokens); $j++) { $colName = $tokens[$j]; $this->colnames[] = $colName; $this->colDict[$colName] = $j - $first_col_idx; } continue; } //Datenzeile: $data_y_idx = $i; if ($this->has_colnames) { $data_y_idx = $i - 1; } // check expected column count if (count($tokens) == 1 and mb_strlen($tokens[0]) == 0) { // tolerate empty lines: // nop } else { if (count($tokens) != $should_be_token_count) { FX::warn("A UTF8-txt line does not have the expected column count (" . count($tokens) . " <-> " . $should_be_token_count . ", line #" . $i . ': ' . $line . ').'); } } if ($this->has_rownames) { $this->rownames[$data_y_idx] = $tokens[0]; } for ($j = $first_col_idx; $j < count($tokens); $j++) { if (!isset($this->data_matrix[$data_y_idx])) { $this->data_matrix[$data_y_idx] = array(); } $data_x_idx = $j; if ($this->has_rownames) { $data_x_idx = $j - 1; } //EXCEL national number format patch... if (!preg_match("/[a-zA-Z!_:]/", $tokens[$j])) { $tokens[$j] = str_replace(",", ".", $tokens[$j]); } $this->data_matrix[$data_y_idx][$data_x_idx] = $tokens[$j]; } } }