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! Link to comment https://forums.phpfreaks.com/topic/245783-php-wildcard/ 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 Link to comment https://forums.phpfreaks.com/topic/245783-php-wildcard/#findComment-1262387 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) ?> Link to comment https://forums.phpfreaks.com/topic/245783-php-wildcard/#findComment-1262399 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"); Link to comment https://forums.phpfreaks.com/topic/245783-php-wildcard/#findComment-1262436 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.