• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

taking all the files in one directory and assigning them their own variable ?

GregT

Waffles!!
NLC
how would i go about taking all the files in one directory and assigning them their own variable ? i need to have every filename.tmpl assigned to their own $filename_tmpl variable ? how (if possible) would i do this ? it needs to be in php.
 
PHP:
$h=opendir('.');
while (($f=readdir($h))!==false) if(is_file($f)) ${str_replace('.', '_', $f)}=$f ;
 
$h=opendir('.') : Opens current directory and returns a handle ($h) for later uses .

while (($f=readdir($h))!==false) : Reads contents of that directory ( readdir($h) ) until all files & subdirs were be read (!==false) and assignes the file name to $f .

if(is_file($f)) : Checkes if $f is a file (it may be a sub directory of the main dir ('.') ) .

${str_replace('.', '_', $f)}=$f : Makes a variable ($VARNAME) with the name of $f which the '.'s are replaced by '_' (str_replace('.', '_', $f)) .
 
Last edited:
Back
Top