$key) { $headers[$idx] = trim($key); } continue; } $row = array(); foreach($headers as $idx => $key) { if (!$key) continue; $row[$key] = (isset($raw_row[$idx])?$raw_row[$idx]:null); } $rows[] = $row; } fclose($fd); echo "done.\n"; if (!$rows) die("CSV file is empty ?\n"); echo count($rows)." loaded from CSV file.\n"; return $rows; } function mb_ucfirst($str) { $fc = mb_strtoupper(mb_substr($str, 0, 1)); return $fc.mb_substr($str, 1); } function _sort($string) { return preg_replace('~&([a-z]{1,2})(acute|cedil|circ|grave|lig|orn|ring|slash|tilde|uml);~i', '$1' . chr(255) . '$2', htmlentities($string, ENT_QUOTES, 'UTF-8')); } function export_nomenclature($array, $fd, $prefix="", $fix_encoding=false) { fwrite($fd, $prefix."array (\n"); array_multisort(array_map('_sort', $array), $array); foreach ($array as $key => $value) { if ($fix_encoding) $key = iconv($fix_encoding[0], $fix_encoding[1], $key); fwrite($fd, $prefix." '".str_replace("'", "\\'", strval($key))."' => "); if (is_array($value)) { export_nomenclature($value, $fd, $prefix." ", $fix_encoding); fwrite($fd, ",\n"); } else { $value = var_export($value, true); if ($fix_encoding) $value = iconv($fix_encoding[0], $fix_encoding[1], $value); fwrite($fd, "$value,\n"); } } fwrite($fd, $prefix.");\n"); }