appending a file based on file name in php
Moderator: General Moderators
appending a file based on file name in php
say i have a series of files in a folder (area1.php,area2.php,area3.php....area75.php). What I want to do is create a script that finds the last one (area75.php if sorted by name) and echos the new name(area76.php). How would i go about creating this?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: appending a file based on file name in php
Perhaps something like
Code: Select all
function getNextArea($dir)
{
$files = array();
foreach (glob("area*.php") as $filename) {
$files[] = basename(substr($filename, -4));
}
return max($files) + 1;
}Re: appending a file based on file name in php
I'm not sure why you would create a new php file that many times...that's what databases are for. In any case you should look at these two manual pages:
http://www.php.net/manual/en/function.natsort.php
http://us3.php.net/manual/en/function.readdir.php
http://www.php.net/manual/en/function.natsort.php
http://us3.php.net/manual/en/function.readdir.php