iSimpleDesign
iSimpleDesign

Reputation: 403

Just show folders with preg match php

i am looking for a way to just show folders in php.

i am getting files like this returned from my amazon foreach loop using undesigneds s3 class.

Computer Fix Files/files/driver-ml-dlan-usb-windows-r2.exe

here my foreach.

foreach ($contents as $file){

    $folder = rtrim($file['name'], "/");

    if (!preg_match("/[0-9\.\-\_]/i", $folder)) { ?>

                <?php echo $folder; ?>

                <?php } 

    } 

ok this kinda works but what i really want to do is just list the first folder.

so instead of this.

Computer Fix Files/files/

it would just show.

Computer Fix Files

any help please????

Upvotes: 0

Views: 391

Answers (2)

acme
acme

Reputation: 14856

echo reset(explode('/', $folder));

should work.

Upvotes: 1

Dan Grossman
Dan Grossman

Reputation: 52372

echo substr($folder, 0, strpos($folder, '/'));

Upvotes: 2

Related Questions