drmota Posted August 26, 2011 Share Posted August 26, 2011 Hello, I am using this PHP script which needs to open several different files with similar names and extensions. This means: fopen(file_1.txt); However, I have about 300 of those files which I need to open and I don't want to rename them one by one. PERL had this awesome feature where you could create a variable with an asterix (wildcard) which would then find anything matching, using a wildcard. Something like: fopen(file_*.txt); ^Would open all files which had file_SOMETHING.txt in them. So is there anything like this in PHP? thanks in advance! Quote Link to comment Share on other sites More sharing options...
codefossa Posted August 26, 2011 Share Posted August 26, 2011 http://www.php.net/manual/en/function.glob.php Quote Link to comment Share on other sites More sharing options...
voip03 Posted August 26, 2011 Share Posted August 26, 2011 <?php function openFile($file) { $file=fopen("$file","r"); } $file='welcome.txt';// demo name $newFile= openFile($file) ?> Quote Link to comment Share on other sites More sharing options...
silkfire Posted August 26, 2011 Share Posted August 26, 2011 glob() is your answer mate. But if there order is continous, why can't you make a loop? for ($i = 1; $i < 300; $i++) $file = fopen("file_$i.txt"); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.