Reputation: 1
I have a list of files in a directory and we want them to be numbered like this:
Each file is already numbered, we just need to "extract" the number from the file name. How can I do it in PHP?
Thanks a lot
Upvotes: 0
Views: 118
Reputation: 27733
I'm sure there are many ways to solve your problem. This might work:
$path = '/Library/Of/MyPC/path/to/files/';
$numbers = filter_var_array(array_values(glob($path . "*")), FILTER_SANITIZE_NUMBER_INT);
var_dump($numbers);
array(3) {
[0]=>
string(1) "1"
[1]=>
string(1) "2"
[2]=>
string(1) "3"
}
If it did not work, you may look into these or similar links 1, 2, 3, 4, 5, which might help you.
Upvotes: 1