English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Tutoriel PHP de base

Tutoriel PHP avancé

PHP & MySQL

Manuel de référence PHP

Utilisation et exemple de la fonction glob() PHP

PHP Filesystem Référence Manuel

La fonction glob() peut retourner un tableau contenant les noms de fichiers ou les répertoires correspondant aux motifs spécifiés. Cette fonction peut retourner un tableau contenant les fichiers/Tableau de répertoires, sinon retourne false.

Syntaxe

array glob ( string $pattern [, int $flags = 0 ] )

La fonction glob() peut rechercher tous les chemins d'accès correspondant aux règles utilisées par glob() et est similaire aux règles utilisées par un shell ordinaire.

Exemple1

<?php
   print_r(glob("/PhpProject/php/*.txt");
?>

Résultat de la sortie

Array
(
    [0] => /PhpProject/php/phptest1.txt
    [1] => /PhpProject/php/phptest2.txt
    [2] => /PhpProject/php/phptest3.txt
    [3] => /PhpProject/php/phptest4.txt
    [4] => /PhpProject/php/phptest5.txt
    [5] => /PhpProject/php/phptest6.txt
    [6] => /PhpProject/php/phptest7.txt
    [7] => /PhpProject/php/phptest8.txt
    [8] => /PhpProject/php/phptest9.txt
    [9] => /PhpProject/php/phptest10.txt
)

Exemple2

<?php
   foreach(glob("/PhpProject/php/*.txt") as $filename) {
      echo "\$filename taille " . filesize(\$filename) . "\n";
   }
?>

Résultat de la sortie

/PhpProject/php/phptest1.txt taille 223
/PhpProject/php/phptest2.txt taille 254
/PhpProject/php/phptest3.txt taille 275
/PhpProject/php/phptest4.txt taille 214
/PhpProject/php/phptest5.txt taille 269
/PhpProject/php/phptest6.txt taille 235
/PhpProject/php/phptest7.txt taille 287
/PhpProject/php/phptest8.txt taille 298
/PhpProject/php/phptest9.txt taille 209
/PhpProject/php/phptest10.txt taille 265

PHP Filesystem Référence Manuel