Counting Numbers

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hawkeye177
Forum Newbie
Posts: 8
Joined: Wed Nov 27, 2002 7:41 pm

Counting Numbers

Post 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
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post 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
hawkeye177
Forum Newbie
Posts: 8
Joined: Wed Nov 27, 2002 7:41 pm

Post 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.
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post 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
Post Reply