Get filename that has no extension using foreach (glob ())

2

How to get only files without extension?

examples

1bdfe4baf9061c3667ded70d8f66142c

2a0daf2d8d5b7ea1813c7a84b146d092

91e3b288eab8d59598a52221296f8995

 $f=glob("*");
 foreach ($f as $arquivo) {
 echo "$arquivo<br>";
 }
 //Neste caso esta exibindo todos arquivos
    
asked by anonymous 09.09.2016 / 07:15

1 answer

3

You can use:

It would look something like:

<?php

$arquivos = array_filter(glob('*'), function ($path) {
    return strpos(basename($path), '.') === false;
});

foreach ($arquivos as $arquivo) {
    echo "$arquivo<br>";
}

I got it wrong, I removed this part:

You can use pathinfo like this:

<?php

$arquivos = glob("*");

foreach ($arquivos as $arquivo) {
    $arquivo = pathinfo($arquivo, PATHINFO_FILENAME);

    echo "$arquivo<br>";
}

    
09.09.2016 / 09:45