function filtre_text_csv_dist($t) { include_spip('inc/csv'); list($entete, $lignes) = analyse_csv($t); foreach ($lignes as &$l) { $l = join('|', $l); } $corps = join("\n", $lignes) . "\n"; $corps = $caption . "\n|{{" . join('}}|{{', $entete) . "}}|" . "\n|" . str_replace("\n", "|\n|", $corps); $corps = str_replace('"#', '"', $corps); include_spip('inc/texte'); return propre($corps); }
/** * csv -> tableau * @param string $u * @return array|bool */ function inc_csv_to_array_dist($u) { include_spip('inc/csv'); list($entete, $csv) = analyse_csv($u); array_unshift($csv, $entete); include_spip('inc/charsets'); foreach ($entete as $k => $v) { $v = strtolower(preg_replace(',\\W+,', '_', translitteration($v))); foreach ($csv as &$item) { $item[$v] =& $item[$k]; } } return $csv; }
/** * csv -> tableau * @param string $u * @return array|bool */ function inc_csv_to_array_dist($u) { include_spip('inc/csv'); list($entete, $csv) = analyse_csv($u); array_unshift($csv, $entete); include_spip('inc/charsets'); $i = 1; foreach ($entete as $k => $v) { if (trim($v) == "") { $v = "col" . $i; } // reperer des eventuelles cases vides if (is_numeric($v) and $v < 0) { $v = "__" . $v; } // ne pas risquer d'ecraser une cle numerique if (is_numeric($v)) { $v = "_" . $v; } // ne pas risquer d'ecraser une cle numerique $v = strtolower(preg_replace(',\\W+,', '_', translitteration($v))); foreach ($csv as &$item) { $item[$v] =& $item[$k]; } $i++; } return $csv; }