- explode: documentation ( source)
<?php
$folders = array(
'test/something.txt',
'test/hello.txt',
'test/another-folder/myfile.txt',
'test/another-folder/kamil.txt',
'test/another-folder/john/hi.txt'
);
foreach ($folders as $file) {
$parts = explode("/", $file);
echo $parts[0].'<br/>';
}