0

How do I get only the file name instead of the path + file name?

foreach(glob('./item/*.txt') as $filename){
   echo $filename;
}
Becky
  • 5,467
  • 9
  • 40
  • 73
  • If you `chdir()` to move into the specific directory before calling `glob()`, then you'll get no path in your strings. – mickmackusa Oct 06 '22 at 10:51

1 Answers1

1

Use basename($filename) to get the filename of the file. Check the documentation here: http://php.net/manual/en/function.basename.php

Lionel Chan
  • 7,894
  • 5
  • 40
  • 69