Page 1 of 1

Counting Numbers

Posted: Wed Dec 25, 2002 5:35 pm
by hawkeye177
Hi. I'm working on a script that takes a number in a line and adds it to the number on the next line... Is there a way i can do this?

Code: Select all

<?php
	$data1 = XXXXX@XXXXX.COM, 64, 02/11/02, 02:58, 02/11/28, 16:00
XXXXX@XXXXX.COM, 880, 02/11/07, 19:32, 02/12/07, 12:12
XXXXX@XXXXX.COM, 1713, 02/11/07, 20:56, 02/12/07, 23:13
XXXXX@XXXXX.COM, 3043, 02/11/08, 02:16, 02/12/07, 23:49';	 

$data = preg_split("!\r|\n!", $data1, -1, PREG_SPLIT_NO_EMPTY); 
foreach($data as $line) 
&#123; 
$domain = strstr($line, ',');

$rest = substr("$domain", 1);    

$separat = ",";
$string = substr($rest, 0, strlen($rest)-strlen (strstr ($rest,$separat)));
print $string; // Prints 64 880 1713 3043
&#125;

?>
Is there a way i can add what it printed? It should get 5700.
Thanks

Posted: Thu Dec 26, 2002 7:07 am
by BDKR
Did you write this? The reason I'm asking is becuase if you did, you shouldn't have any problems figuring out how to do what you need. It's not at all a bad piece of code and is by itself more complex than what you're talking about doing.

Cheers,
BDKR

Posted: Thu Dec 26, 2002 10:40 am
by hawkeye177
Yeah i wrote that..

Yeah after playing with it for hours i decided just to go into word and replace the blanks to "+" and writing a simple script to calculate it all.

Posted: Thu Dec 26, 2002 1:47 pm
by BDKR
Well, this is all I did...

Code: Select all

<?php
$data1 = 'XXXXX@XXXXX.COM, 64, 02/11/02, 02:58, 02/11/28, 16:00
XXXXX@XXXXX.COM, 880, 02/11/07, 19:32, 02/12/07, 12:12
XXXXX@XXXXX.COM, 1713, 02/11/07, 20:56, 02/12/07, 23:13
XXXXX@XXXXX.COM, 3043, 02/11/08, 02:16, 02/12/07, 23:49';  
$data = preg_split("!\r|\n!", $data1, -1, PREG_SPLIT_NO_EMPTY); 
foreach($data as $line)
  {
  $domain = strstr($line, ',');
  $rest = substr("$domain", 1);   
  $separat = ",";
  $string = substr($rest, 0, strlen($rest)-strlen (strstr ($rest,$separat)));
  print $string; // Prints 64 880 1713 3043
  $x=$x+$string;
  }
print "\n".$x."\n";
?>
Cheers,
BDKR