Jump to content

1 + 2 = 3 (add up of infinite text counter files)


ted_chou12

Recommended Posts

i have infinite number of files in a folder, and each of those txt files has a number, what i want is add all of those numbers together,
so far, this is what ive got
$namearray = array("forum"); // File names you want to exclude
$extarray = array("xml","jpg","php","css","bmp","png","html");  //extension you want to exclude
$files = array();
if ($handle = opendir(".")) {
  while (false !== ($file = readdir($handle))) {
    if($file != "." && $file != ".."){
      if (filetype($file) == "file" || filetype($file) == "dir"){
      $filearray = explode(".", $file);
      $files[$filearray[0]] = $filearray[1];
      }
    }
  }
closedir($handle);
}
foreach($files as $name => $ext){
  if(in_array($name, $namearray, false) || in_array($ext, $extarray, false)){
  } else {
  foreach(@file("homework/$name.txt") as $v){list($topic,$category,$number,$datetime,$name,$username,$message) = explode("#",$v);}
  $repliesaa = file_get_contents("topic$number-replies.php")."\n";}


it lists out the txt files but i am having trouble adding the numbers up, can anyone give me some ideas
Link to comment
Share on other sites

infinite number of files eh?  I need to get me one of those HD's ;)

Try this... count will hold your number of files.
[code]
...

$count = 0;

foreach($files as $name => $ext){

  ++ $count;

if(in_array($name, $namearray, false) || in_array($ext, $extarray, false)){
  } else {
  foreach(@file("homework/$name.txt") as $v){list($topic,$category,$number,$datetime,$name,$username,$message) = explode("#",$v);}
  $repliesaa = file_get_contents("topic$number-replies.php")."\n";
}

[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.