Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php: how to read only txt files in a directory

Tags:

php

i have a folder called XXX it contains .jpg .gif .txt .... etc

i want only to read .txt files how to do that ?

Thanks

like image 529
trrrrrrm Avatar asked Dec 04 '22 11:12

trrrrrrm


2 Answers

You can use glob to get an array of file names that match a given pattern. Here’s the example from the manual page:

foreach (glob("*.txt") as $filename) {
    echo "$filename size " . filesize($filename) . "\n";
}
like image 129
Gumbo Avatar answered Dec 29 '22 03:12

Gumbo


<?php
foreach (glob("*.txt") as $filename) {
    echo "$filename size " . filesize($filename) . "\n";
}
?>
like image 35
Ward Bekker Avatar answered Dec 29 '22 01:12

Ward Bekker