我使用glob()解析存储在服务器上的XML文件,下面的代码是.
$files = glob('/home/website/dataupload/*.{xml}', GLOB_BRACE);
foreach($files as $file) {
// ...
}这些文件存储在“dataupload”后面的两个子目录中,我试图将第一个子目录的名称作为变量返回。例如,结构可能是这样的..。
/home/website/dataupload/brand-here/file-type/fileone.xml我不关心第二个目录('file-type'),但是需要能够将第一个目录(‘be’)作为变量返回,例如$brandName。
是否可以这样做?如果可以的话,我可否获得协助,以达致这个目的?
发布于 2014-02-24 22:13:56
我使用以下代码解决了这个问题。这可能不是最好的办法,但这是我如何使它工作!
function recursiveGlob($dir, $ext) {
foreach ($globFiles as $file) {
$brandpath = dirname(dirname($file));
$brandname = substr( $brandpath, strrpos( $brandpath, '/' )+1 );
}
}
recursiveGlob('/home/website/dataupload', 'xml');它工作得很好,虽然我确信它可以用不同的方式来完成,但它的目的是:-)
https://stackoverflow.com/questions/21997410
复制相似问题