Jump to content

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

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.