Jump to content

Problem with split and merge .txt data


roime

Recommended Posts

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";

 

?>

Link to comment
https://forums.phpfreaks.com/topic/133767-problem-with-split-and-merge-txt-data/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.