IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

[Tableaux] Tri naturel avec natcasesort()


Sujet :

Langage PHP

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    18
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 18
    Points : 9
    Points
    9
    Par défaut [Tableaux] Tri naturel avec natcasesort()
    Bonjour à tous,

    J'ai un soucis avec la fonction natcasesort() sur mon script PHP.
    J'ai un array() avec du contenu de type chemin d'accès sous Linux (ex : /test/distrib/debian/i386), je fais ceci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    $stock = array(); // création du tableau
    while(condition) $stock[] = $objet; // ajout des valeurs
    natcasesort($stock); // tri naturel sans prise en compte de la case
    foreach...

    Aucune erreur reportée par PHP, mais le tri ne s'effectue pas.

    Quelqu'un a-t'il une idée ?

    Merci

    Configuration: Linux Debian Etch 2.6.18
    Dernières versions de Apache2 et PHP5

  2. #2
    Membre émérite
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    1 448
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 448
    Points : 2 284
    Points
    2 284
    Par défaut
    Salut,

    Si $objet est un Objet, je pense que le tri ne s'effectue car la comparaison effectuée n'est pas correcte. En effet dans ce cas il faudrait indiquer à PHP de trier sur $Objet->chemin, par exemple.

    Autrment c'est peut être parceque tes index ne sont pas réattribués. Mais normalement avec foreach, sa devrait être ok. Essaie tout de même un $stock = array_values($stock); avant le foreach. Dès fois que.

    bye

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    18
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 18
    Points : 9
    Points
    9
    Par défaut
    Merci de ta réponse.

    J'ai testé le array_values(), ça ne marche pas.

    Pour ce qui est de la variable $objet, ce n'est pas un objet de POO, c'est simplement une chaine de caractères désignant un chemin d'accès comme je l'ai précisé en haut, et dont la valeur s'ajoute dans une case du array() $stock.

    Bref, toujours bloqué

  4. #4
    Membre émérite
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    1 448
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 448
    Points : 2 284
    Points
    2 284
    Par défaut
    Au fait tu es sur php5 ? ou php4 ?
    Car si tu es sous php4, tu peux essayer un &$stock.

    Parceque sur php5 ce code fonctionne :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
     
    <?
    	$stock 	= array();
    	$stock[] 	= "/toto/titi/atta";
    	$stock[] 	= "/fsdgsdfdsfsdf/atta";
    	$stock[] 	= "/cvbcvbcvvcv/titi/atta";
    	$stock[] 	= "/ytuynjui,ui/titi/atta";
    	$stock[] 	= "/aaaaa/titi/atta";
     
    	natcasesort($stock); 
     
    	echo "<pre>";
    	var_dump($stock);
    	echo "</pre>";
    ?>
    Avec comme résultat :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    array(5) {
      [4]=>
      string(16) "/aaaaa/titi/atta"
      [2]=>
      string(22) "/cvbcvbcvvcv/titi/atta"
      [1]=>
      string(19) "/fsdgsdfdsfsdf/atta"
      [0]=>
      string(15) "/toto/titi/atta"
      [3]=>
      string(22) "/ytuynjui,ui/titi/atta"
    }
    bye

  5. #5
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    18
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 18
    Points : 9
    Points
    9
    Par défaut
    Regarde ce qui est écrit en grisé en bas de mon premier message

    Apache 2 et PHP 5

    Mais ça ne marche pas...

  6. #6
    Membre émérite
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    1 448
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 448
    Points : 2 284
    Points
    2 284
    Par défaut
    Ah ouais ! Je n'avais vu comme cela en gris.


    Même mon code ne fonctionne pas ? Auquel procède à une mise à jour de php car là ce serait un bug, même si rien n'est déclaré sur php bugs (enfin j'ai fait une rapide recherche..).

    bye

  7. #7
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    18
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 18
    Points : 9
    Points
    9
    Par défaut
    Ton code marche effectivement, mais je ne vois pas pourquoi le mien non

  8. #8
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    18
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 18
    Points : 9
    Points
    9
    Par défaut
    Alors j'ai trouvé la raison mais je ne sais pas pourquoi ça fait ça.

    C'est parce que j'ai une condition sur le remplissage du tableau $stock[] que ça se produit :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    while(...) {
           if($fichier == "pwet" || $fichier == "prout" || $fichier == "camembert") $stock[] = $dossier.$fichier;
           ...
    }
     
    natcasesort($stock);
     
    foreach($stock as $contenu) {
            echo $contenu;
            ...
    }
    Je ne vois pas du tout comment remédier à ce problème.

    Une idée ?

    PS : toutes les fonctions de tri (sort, rsort, asort... font pareil)

  9. #9
    Membre émérite
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    1 448
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 448
    Points : 2 284
    Points
    2 284
    Par défaut
    tu as un système de cache style APC d'activé ?

  10. #10
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    18
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 18
    Points : 9
    Points
    9
    Par défaut
    Non, aucun système de cache

  11. #11
    Membre habitué
    Avatar de savageman86
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    105
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Octobre 2006
    Messages : 105
    Points : 199
    Points
    199
    Par défaut
    Et en essayant de feinter comme ceci ?
    usort($stock, 'strcasecmp');

    Un print_r() avant te donne le bon truc ?
    Et un print_r(natcasesort($stock)); te retourne-t-il "true" ?

  12. #12
    Membre émérite
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    1 448
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 448
    Points : 2 284
    Points
    2 284
    Par défaut
    Trop bizarre. Tu peux nous faire un print_r de ton $stock ?

    bye

  13. #13
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    18
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 18
    Points : 9
    Points
    9
    Par défaut
    Citation Envoyé par savageman86 Voir le message
    Et en essayant de feinter comme ceci ?
    usort($stock, 'strcasecmp');

    Un print_r() avant te donne le bon truc ?
    Et un print_r(natcasesort($stock)); te retourne-t-il "true" ?
    Le usort($stock, 'strcasecmp'); ne marche pas.
    Et le print_r(natcasesort($stock)); retourne true plusieurs fois (genre 11 pour une case, 11111 pour une autre, 111... bizarre)

    Alors attention je déballe le contenu de mon array, ça pique !

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    array(1) {
      [0]=>
      string(49) "/tftpboot/Distributions/x86-64/CentOS_5.1/vmlinuz"
    }
     
    Distributions/x86-64/CentOS_5.1/vmlinuz
     
    array(1) {
      [0]=>
      string(52) "/tftpboot/Distributions/x86-64/Fedora_Core_3/vmlinuz"
    }
     
    Distributions/x86-64/Fedora_Core_3/vmlinuz
     
    array(0) {
    }
     
    array(1) {
      [0]=>
      string(76) "/tftpboot/Distributions/x86-64/Debian_4.0_Etch/debian-installer/ia64/vmlinuz"
    }
     
    Distributions/x86-64/Debian_4.0_Etch/debian-installer/ia64/vmlinuz
     
    array(0) {
    }
     
    array(0) {
    }
     
    array(1) {
      [0]=>
      string(52) "/tftpboot/Distributions/x86-64/Fedora_Core_7/vmlinuz"
    }
     
    Distributions/x86-64/Fedora_Core_7/vmlinuz
     
    array(0) {
    }
     
    array(1) {
      [0]=>
      string(81) "/tftpboot/Distributions/x86-64/Debian_3.1_Sarge/debian-installer/ia64/2.6/vmlinuz"
    }
     
    Distributions/x86-64/Debian_3.1_Sarge/debian-installer/ia64/2.6/vmlinuz
     
    array(1) {
      [0]=>
      string(77) "/tftpboot/Distributions/x86-64/Debian_3.1_Sarge/debian-installer/ia64/vmlinuz"
    }
     
    Distributions/x86-64/Debian_3.1_Sarge/debian-installer/ia64/vmlinuz
     
    array(0) {
    }
     
    array(0) {
    }
     
    array(1) {
      [0]=>
      string(52) "/tftpboot/Distributions/x86-64/Fedora_Core_4/vmlinuz"
    }
     
    Distributions/x86-64/Fedora_Core_4/vmlinuz
     
    array(1) {
      [0]=>
      string(52) "/tftpboot/Distributions/x86-64/Fedora_Core_8/vmlinuz"
    }
     
    Distributions/x86-64/Fedora_Core_8/vmlinuz
     
    array(1) {
      [0]=>
      string(52) "/tftpboot/Distributions/x86-64/Fedora_Core_6/vmlinuz"
    }
     
    Distributions/x86-64/Fedora_Core_6/vmlinuz
     
    array(1) {
      [0]=>
      string(49) "/tftpboot/Distributions/x86-64/CentOS_4.6/vmlinuz"
    }
     
    Distributions/x86-64/CentOS_4.6/vmlinuz
     
    array(0) {
    }
     
    array(0) {
    }
     
    array(0) {
    }
     
    array(0) {
    }
     
    array(1) {
      [0]=>
      string(86) "/tftpboot/Distributions/x86-64/Ubuntu_6.06.2_Dapper_Drake/ubuntu-installer/amd64/linux"
    }
     
    Distributions/x86-64/Ubuntu_6.06.2_Dapper_Drake/ubuntu-installer/amd64/linux
     
    array(0) {
    }
     
    array(0) {
    }
     
    array(1) {
      [0]=>
      string(52) "/tftpboot/Distributions/x86-64/Fedora_Core_2/vmlinuz"
    }
     
    Distributions/x86-64/Fedora_Core_2/vmlinuz
     
    array(1) {
      [0]=>
      string(52) "/tftpboot/Distributions/x86-64/Fedora_Core_5/vmlinuz"
    }
     
    Distributions/x86-64/Fedora_Core_5/vmlinuz
     
    array(0) {
    }
     
    array(1) {
      [0]=>
      string(59) "/tftpboot/Distributions/Acronis/recovery-manager/kernel.dat"
    }
     
    Distributions/Acronis/recovery-manager/kernel.dat
     
    array(0) {
    }
     
    array(1) {
      [0]=>
      string(47) "/tftpboot/Distributions/i386/CentOS_5.1/vmlinuz"
    }
     
    Distributions/i386/CentOS_5.1/vmlinuz
     
    array(1) {
      [0]=>
      string(50) "/tftpboot/Distributions/i386/Fedora_Core_3/vmlinuz"
    }
     
    Distributions/i386/Fedora_Core_3/vmlinuz
     
    array(0) {
    }
     
    array(0) {
    }
     
    array(0) {
    }
     
    array(0) {
    }
     
    array(1) {
      [0]=>
      string(72) "/tftpboot/Distributions/i386/Debian_4.0_Etch/debian-installer/i386/linux"
    }
     
    Distributions/i386/Debian_4.0_Etch/debian-installer/i386/linux
     
    array(0) {
    }
     
    array(0) {
    }
     
    array(1) {
      [0]=>
      string(50) "/tftpboot/Distributions/i386/Fedora_Core_7/vmlinuz"
    }
     
    Distributions/i386/Fedora_Core_7/vmlinuz
     
    array(0) {
    }
     
    array(0) {
    }
     
    array(0) {
    }
     
    array(1) {
      [0]=>
      string(77) "/tftpboot/Distributions/i386/Debian_3.1_Sarge/debian-installer/i386/2.6/linux"
    }
     
    Distributions/i386/Debian_3.1_Sarge/debian-installer/i386/2.6/linux
     
    array(0) {
    }
     
    array(1) {
      [0]=>
      string(73) "/tftpboot/Distributions/i386/Debian_3.1_Sarge/debian-installer/i386/linux"
    }
     
    Distributions/i386/Debian_3.1_Sarge/debian-installer/i386/linux
     
    array(0) {
    }
     
    array(0) {
    }
     
    array(1) {
      [0]=>
      string(50) "/tftpboot/Distributions/i386/Fedora_Core_4/vmlinuz"
    }
     
    Distributions/i386/Fedora_Core_4/vmlinuz
     
    array(1) {
      [0]=>
      string(50) "/tftpboot/Distributions/i386/Fedora_Core_8/vmlinuz"
    }
     
    Distributions/i386/Fedora_Core_8/vmlinuz
     
    array(1) {
      [0]=>
      string(50) "/tftpboot/Distributions/i386/Fedora_Core_6/vmlinuz"
    }
     
    Distributions/i386/Fedora_Core_6/vmlinuz
     
    array(1) {
      [0]=>
      string(47) "/tftpboot/Distributions/i386/CentOS_4.6/vmlinuz"
    }
     
    Distributions/i386/CentOS_4.6/vmlinuz
     
    array(0) {
    }
     
    array(0) {
    }
     
    array(0) {
    }
     
    array(0) {
    }
     
    array(1) {
      [0]=>
      string(83) "/tftpboot/Distributions/i386/Ubuntu_6.06.2_Dapper_Drake/ubuntu-installer/i386/linux"
    }
     
    Distributions/i386/Ubuntu_6.06.2_Dapper_Drake/ubuntu-installer/i386/linux
     
    array(0) {
    }
     
    array(0) {
    }
     
    array(1) {
      [0]=>
      string(50) "/tftpboot/Distributions/i386/Fedora_Core_2/vmlinuz"
    }
     
    Distributions/i386/Fedora_Core_2/vmlinuz
     
    array(1) {
      [0]=>
      string(50) "/tftpboot/Distributions/i386/Fedora_Core_5/vmlinuz"
    }
     
    Distributions/i386/Fedora_Core_5/vmlinuz
     
    array(0) {
    }
     
    array(0) {
    }
     
    array(0) {
    }
     
    array(0) {
    }
    Voilà.

  14. #14
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    18
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 18
    Points : 9
    Points
    9
    Par défaut
    Vous voulez le code du script ?

  15. #15
    Membre émérite
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    1 448
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 448
    Points : 2 284
    Points
    2 284
    Par défaut
    Tu peux faire un print_t juste avant le natcasesort($stock);

    Car le tableau que tu as donnés, est en définitive une série de tableau. Du coup je vois pas trop ce que tu tries car tout tes tableaux ont au plus une et une seule clef.

    MErci,
    a+

  16. #16
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    18
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 18
    Points : 9
    Points
    9
    Par défaut
    Un print_t ?? Fatal error: Call to undefined function print_t()

    Si c'est du print_r() que tu parles, le précédent était avant le natcasesort().

  17. #17
    Membre habitué
    Avatar de savageman86
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    105
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Octobre 2006
    Messages : 105
    Points : 199
    Points
    199
    Par défaut
    En fait, tu as des tableaux dans ton tableau ?

  18. #18
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    18
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 18
    Points : 9
    Points
    9
    Par défaut
    Bah théoriquement je suis censé avoir des chaines dans mon tableau, mais d'après ce que je comprend, c'est pas le cas, c'est des tableaux, mais pourquoi ? O_o

  19. #19
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    18
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 18
    Points : 9
    Points
    9
    Par défaut
    Bon aller j'envoie le script :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    	function ScanDossier($dossier) {
    		$stock = array(); //Définition du tableau qui stock la sortie
    		if(!preg_match("/^.*\/$/", $dossier)) $dossier .= '/'; //Ajout du slash à la fin du chemin s'il n'y est pas
    		$manip = opendir($dossier); //Ouverture du repertoire demandé
    		if($manip != false) { //Si pas d'erreur d'ouverture du dossier, on lance le scan
    			while($fichier = readdir($manip)) { //Parcours du repertoire
    				if($fichier != '.' && $fichier != '..') {
    					if($fichier == "vmlinuz"
    					 || $fichier == "linux"
    					 || $fichier == "kernel.dat") $stock[] = $dossier.$fichier;
    					if(is_dir($dossier.$fichier)) ScanDossier($dossier.$fichier);
    				}
    			}
    			closedir($manip); //Fermeture du repertoire
    			natcasesort($stock);
    			foreach($stock as $valeur) { //Défilement et affichage du contenu du tableau
    					$valeur = str_replace('/tftpboot/', '', $valeur);
    					echo "<option value='$valeur'>$valeur";
    			}
    		return true;
    		} else return false;
    	}
    Et je fais appel à la fonction comme cela :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    <select name='kernel'>
    	<option value='' selected>
    		S&eacute;lectionnez un kernel dans la liste...
    	<? ScanDossier("/tftpboot"); ?>
    </select>
    Vous y voyez plus clair ?

  20. #20
    Membre émérite
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    1 448
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 448
    Points : 2 284
    Points
    2 284
    Par défaut
    Ok,

    je l'ai modifié ainsi, tu me diras si c'est ok et si tu comprends, ou pas.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    <?php
    function ScanDossier($dossier)
    {
    	$stock = array(); //Définition du tableau qui stock la sortie
    	
    	if(!preg_match("/^.*\/$/", $dossier))
    		$dossier .= '/'; //Ajout du slash à la fin du chemin s'il n'y est pas
    	
    	$manip = opendir($dossier); //Ouverture du repertoire demandé
    	
    	if($manip != false)
    	{ //Si pas d'erreur d'ouverture du dossier, on lance le scan
    		while($fichier = readdir($manip))
    		{ //Parcours du repertoire
    			if($fichier != '.' && $fichier != '..')
    			{
    				if($fichier == "vmlinuz"
    				 || $fichier == "linux"
    				 || $fichier == "kernel.dat" || 1 == 1 ) 
    				{
    					$stock[] = $dossier.$fichier;
    				
    					if(is_dir($dossier.$fichier))
    					{
    						$t = ScanDossier($dossier.$fichier);
    						if( $t !== false )
    							foreach( $t as $index => $valeur )
    								$stock[] = $valeur;
    					}
    				}
    			}
    		}
    		closedir($manip); //Fermeture du repertoire
    		
    		natcasesort($stock);
    		
    		return $stock;
    	}
    	else
    		return false;
    }
    	
    	
    	
    	foreach(ScanDossier("Nouveau dossier") as $valeur)
    	{ //Défilement et affichage du contenu du tableau
    			$valeur = str_replace('/tftpboot/', '', $valeur);
    			echo "<option value='$valeur'>$valeur<br />";
    	}
    ?>
    bye

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. [PHP 5.2] [Tableaux] Tri naturel des valeurs d'un tableau
    Par Riko63 dans le forum Langage
    Réponses: 3
    Dernier message: 03/07/2009, 08h14
  2. [Tableaux] tri tableau avec fonction
    Par ascito dans le forum Langage
    Réponses: 7
    Dernier message: 10/09/2008, 14h21
  3. Réponses: 2
    Dernier message: 04/11/2007, 08h43
  4. [Tableaux] Tri tableau avec underscore et chiffres
    Par __fabrice dans le forum Langage
    Réponses: 4
    Dernier message: 18/10/2006, 17h05
  5. [Tableaux] tri tableau avec date
    Par omelhor dans le forum Langage
    Réponses: 12
    Dernier message: 17/10/2006, 20h24

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo