Split and summ data in .txt file
Posted: Sat Nov 22, 2008 4:37 am
Hi all,
I have a problem on php coding. I have a text file that consists of a data like this
joe.txt;
12
34
32
34
21
23
By using php, i try to split the data into a separated group that consists 2 values such a format like below;
group 1;
12
34
group 2;
32
34
group 3;
21
23
I've successfully writes a script to read all of the values, display them and sum all of them..But i still refused to split them and sum all of them based on their groups..If u guys have an idea then please help me...
Scripts that i had;
<?php
$myFile = "joe.txt";
$handle = fopen($myFile, 'r');
while (!feof($handle))
{
$data = fgets($handle, 512);
echo $data;
echo "<br>";
$total += $data;
}
fclose($handle);
$lines = count(file($myFile));
echo "There are $lines lines in $myFile";
echo "<br>";
echo "Total value was : $total";
?>
I have a problem on php coding. I have a text file that consists of a data like this
joe.txt;
12
34
32
34
21
23
By using php, i try to split the data into a separated group that consists 2 values such a format like below;
group 1;
12
34
group 2;
32
34
group 3;
21
23
I've successfully writes a script to read all of the values, display them and sum all of them..But i still refused to split them and sum all of them based on their groups..If u guys have an idea then please help me...
Scripts that i had;
<?php
$myFile = "joe.txt";
$handle = fopen($myFile, 'r');
while (!feof($handle))
{
$data = fgets($handle, 512);
echo $data;
echo "<br>";
$total += $data;
}
fclose($handle);
$lines = count(file($myFile));
echo "There are $lines lines in $myFile";
echo "<br>";
echo "Total value was : $total";
?>