What is the result between these two PHP codes?

  • Thread starter Thread starter Hello
  • Start date Start date
H

Hello

Guest
Here is the first one:

$someFile = fopen("someData.txt", "r");
$nextItem = fgets($someFile);
while (!feof ($someFile))
{
list($value1, $value2) = split (":", $nextItem);
print ("<p>$value1 $value2</p>)";
$nextItem = fgets($someFile);
}
fclose ($someFile);
print ("<p>$value </p>);

Here is the second one:

$value = 0;
$someFile = fopen("someData.txt", "r");
$nextItem = fgets($someFile);
while (!feof ($someFile))
{
list($value1, $value2) = split (":", $nextItem);
$value = $value $value2;
$nextItem = fgets($someFile);
}
fclose ($someFile);
print ("<p>$value </p>);

Is the first one displays a file containing exactly two lines of data?

is the second one reads a file containing two values on each line and sums the second values on each line?

Can someone please confimr if this is what these PHP programs do? thanx!
 
well, both files have typing errors so neither would run in written form but you might assume that:

the first one, reads complete 'somefile' assuming that each line has two elements separated by ':' and prints them .
'$value' is never initialized and prints blank line.


The second file is similar except:
$value=$value1 $value2; is wrong and has no meaning.
If you put '+ in between $value=$value1+$value2; , $value vould be sum of elements provided that they can be interpreted as numbers.
Upon exit the last result would be printet only.
 
Back
Top