par Gakman » 30 sept. 2010, 15:28
par stealth35 » 28 sept. 2010, 03:35
foreach($dir as $filename => $file) { var_dump($filename); } exit;
par Gakman » 28 sept. 2010, 03:12
J'ai pas compris vers quoi on t'oriente, mais l'erreur dans ton code du premier post vient d'un problème local versus global. Lorsque tu n'utilise pas de fonction, la variable $liste est global et le code la trouve pour l'utiliser. Lorsque tu encapsule ton code dans une fonction, les variables deviennent local et donc ta fonction n'a pas accès à la variable $liste. Il y a deux solutions, introduire $liste dans les arguments de ta fonction ou déclarer $liste comme variable global en début de fonction (inutile dans ce cas ci je pense).
error_reporting(-1); $dir = new DirectoryIterator('heberg2'); foreach($dir as $filename => $file) { var_dump($filename); } exit; foreach($dir as $filename => $file) { preg_match('/^(?P<date>[^-]+)-(?P<category>[^+]+)\+(?P<lieu>.+)$/u', $file->getFilename(), $matches); if($matches) { $temp[$matches['category']][$matches['lieu']][$matches['date']] = $file; ksort($temp); ksort($temp[$matches['category']]); ksort($temp[$matches['category']][$matches['lieu']]); } } $arr = new RecursiveArrayIterator($temp); $rec = new RecursiveIteratorIterator($arr, RecursiveIteratorIterator::SELF_FIRST); foreach($rec as $key => $value) { switch($rec->getDepth()) { case 0: echo '<h1>' . $key . '<h1>'; break; case 1: echo '<h2>' . $key . '<h2>'; break; case 2: echo '<h3>' . $value . '<h3>'; break; default: break; } }
par Spols » 27 sept. 2010, 11:17
par stealth35 » 27 sept. 2010, 02:51
preg_match('/^(?P<date>[^-]+)-(?P<category>[^+]+)\+(?P<lieu>.+)$/u', $file->getFilename(), $matches);
par Gakman » 27 sept. 2010, 02:47
Code : Tout sélectionner
int(0) int(1) int(2)
par stealth35 » 25 sept. 2010, 02:14
par Gakman » 25 sept. 2010, 02:08
Notice: Undefined variable: temp in /mnt/159/sdd/c/3/-/index2.php on line 65 Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Passed variable is not an array or object, using empty array instead' in /mnt/159/sdd/c/3/-/index2.php:65 Stack trace: #0 /mnt/159/sdd/c/3/-/index2.php(65): ArrayIterator->__construct(NULL) #1 {main} thrown in /mnt/159/sdd/c/3/-/index2.php on line 65
$rec = new RecursiveIteratorIterator($arr, RecursiveIteratorIterator::SELF_FIRST);
par stealth35 » 24 sept. 2010, 17:58
Non des dossiers, pas de fichier. exemple simple : 2008-v+tokyo à l'heure actuelle j'utilisais 2 catégories : f = famille v = vacances
preg_match('/^(?P<date>[^-]+)-(?P<category>[^+]+)\+(?P<lieu>.+)$/u', $filename, $matches); if($matches) { $temp[$matches['category']][$matches['lieu']][$matches['date']] = $file; ksort($temp); ksort($temp[$matches['category']]); ksort($temp[$matches['category']][$matches['lieu']]); }
par Gakman » 24 sept. 2010, 16:45
par stealth35 » 24 sept. 2010, 02:50
Se sont des dossiers nommés "date-catégorie+lieu". Il y a des fichiers dedans (des photos et des vidéos) mais c'est sans importance, je les traiterai avec un autre script.
par Gakman » 24 sept. 2010, 00:37
par stealth35 » 23 sept. 2010, 17:31
par Gakman » 23 sept. 2010, 13:57
Notice: Undefined index: category in /mnt/159/sdd/c/3/-/index3.php on line 55 Notice: Undefined index: lieu in /mnt/159/sdd/c/3/-/index3.php on line 55 Notice: Undefined index: date in /mnt/159/sdd/c/3/-/index3.php on line 55 Notice: Undefined index: category in /mnt/159/sdd/c/3/-/index3.php on line 58 Notice: Undefined index: category in /mnt/159/sdd/c/3/-/index3.php on line 59 Notice: Undefined index: lieu in /mnt/159/sdd/c/3/-/index3.php on line 59 -> ces 6 lignes répétées 3 fois au total
par stealth35 » 23 sept. 2010, 02:29
Merci ton aide ! Tel quel ça ne fonctionne pas mais je vais regarder demain, trop fatigué pour comprendre le code visiblement ce soir .