talor123 Posted April 7, 2008 Share Posted April 7, 2008 hey, i need some help with my php code, when i use the fwrite code like ("$file", "a"); how to i make it so the variable file is numbered.. eg: the first "file" to be created will be called "1.html" then the next to be created would be called "2.html".. so it numbers them ... so eventualy there would be say 20 files, there names would be 1.html,2.html,3.html and so on.. thanks for your help Link to comment https://forums.phpfreaks.com/topic/99938-php-number-code/ Share on other sites More sharing options...
Cep Posted April 7, 2008 Share Posted April 7, 2008 You could use a loop <?php $somecontent = "Something"; for($i = 1; $i <= 20; $i++) { $name = "{$i}.html"; if (!$handle = fopen($name, 'a')) { echo "Cannot open file ($name)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === false) { echo "Cannot write to file ($name)"; exit; } echo "Success, wrote ($somecontent) to file ($name)"; fclose($handle); } ?> Its not desirable to do this, but I assume your using fwrite because your in PHP4 Link to comment https://forums.phpfreaks.com/topic/99938-php-number-code/#findComment-511011 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.