php changing values when i read in lines from files, why?

Below is the code. I have commented out alot of it because I am trying to figure out what is going on. I am reading a file in and based on that file I read in a bunch more. When I read in lines from the file data is being changed. Below is an example file:

Time,209,XACC,0.04,YACC,0.86,ZACC,0.19,XSHOCK,0.58,YSHOCK,0.45,ZSHOCK,0.06,Position,standing
Time,210,XACC,0.66,YACC,0,ZACC,0.67,XSHOCK,0.92,YSHOCK,0.87,ZSHOCK,0.32,Position,standing
Time,211,XACC,0.56,YACC,0.74,ZACC,0.47,XSHOCK,0.21,YSHOCK,0.83,ZSHOCK,0.22,Position,standing
Time,212,XACC,0.31,YACC,0.76,ZACC,0.83,XSHOCK,0.48,YSHOCK,0.23,ZSHOCK,0.82,Position,standing
Time,213,XACC,0.18,YACC,0.76,ZACC,0.2,XSHOCK,0.11,YSHOCK,0.82,ZSHOCK,0.56,Position,standing
Time,214,XACC,0.9,YACC,0.25,ZACC,0.24,XSHOCK,0.86,YSHOCK,0.77,ZSHOCK,0.69,Position,standing
Time,215,XACC,0.43,YACC,0.34,ZACC,0.77,XSHOCK,0.68,YSHOCK,0.68,ZSHOCK,0.91,Position,standing
Time,216,XACC,0.96,YACC,0.83,ZACC,0.28,XSHOCK,0.27,YSHOCK,0.26,ZSHOCK,0.71,Position,standing
Time,217,XACC,0.97,YACC,0.12,ZACC,0.03,XSHOCK,0.27,YSHOCK,0.08,ZSHOCK,0.45,Position,standing
Time,218,XACC,0.08,YACC,0.85,ZACC,0.38,XSHOCK,0.37,YSHOCK,0.43,ZSHOCK,0.13,Position,standing
Time,219,XACC,0.01,YACC,0.5,ZACC,0.28,XSHOCK,0.11,YSHOCK,0.5,ZSHOCK,0.49,Position,standing
Time,220,XACC,0.92,YACC,0.54,ZACC,0.69,XSHOCK,0.81,YSHOCK,0.65,ZSHOCK,0.67,Position,standing
Time,221,XACC,0.13,YACC,0.93,ZACC,0.34,XSHOCK,0.72,YSHOCK,0.72,ZSHOCK,0.3,Position,standing
Time,222,XACC,0.01,YACC,0.42,ZACC,0.77,XSHOCK,0.77,YSHOCK,0.7,ZSHOCK,0.02,Position,standing
Time,223,XACC,0.64,YACC,0.81,ZACC,0.9,XSHOCK,0.23,YSHOCK,0.37,ZSHOCK,0.23,Position,standing
Time,224,XACC,0.79,YACC,0.95,ZACC,0.69,XSHOCK,0.27,YSHOCK,0.42,ZSHOCK,0.1,Position,standing
Time,225,XACC,0.82,YACC,0.58,ZACC,0.26,XSHOCK,0.87,YSHOCK,0.7,ZSHOCK,0.28,Position,standing
Time,226,XACC,0.51,YACC,0.58,ZACC,0.13,XSHOCK,0.6,YSHOCK,0.83,ZSHOCK,0.86,Position,standing
Time,227,XACC,0.42,YACC,0.1,ZACC,0.72,XSHOCK,0.28,YSHOCK,0.34,ZSHOCK,0.41,Position,standing
Time,228,XACC,0.18,YACC,0.03,ZACC,0.67,XSHOCK,0.65,YSHOCK,0.38,ZSHOCK,0.81,Position,standing
Time,229,XACC,0.57,YACC,0.5,ZACC,0.14,XSHOCK,0.98,YSHOCK,0.58,ZSHOCK,0.61,Position,standing
Time,230,XACC,0.63,YACC,0.56,ZACC,0.07,XSHOCK,0.78,YSHOCK,0.89,ZSHOCK,0.35,Position,standing
Time,231,XACC,0.65,YACC,0.75,ZACC,0.86,XSHOCK,0.86,YSHOCK,0.33,ZSHOCK,0.6,Position,standing
Time,232,XACC,0.3,YACC,0.48,ZACC,0.28,XSHOCK,0.92,YSHOCK,0.33,ZSHOCK,0.4,Position,standing
Time,233,XACC,0.66,YACC,0.35,ZACC,0.1,XSHOCK,0.99,YSHOCK,0.37,ZSHOCK,0.92,Position,standing
Time,234,XACC,0.82,YACC,0.28,ZACC,0.52,XSHOCK,0.69,YSHOCK,0.44,ZSHOCK,0.94,Position,standing
Time,235,XACC,0.08,YACC,0.52,ZACC,0.47,XSHOCK,0.32,YSHOCK,0.35,ZSHOCK,0.08,Position,standing
Time,236,XACC,0.64,YACC,0.97,ZACC,0.43,XSHOCK,0.49,YSHOCK,0.15,ZSHOCK,0.41,Position,standing
Time,237,XACC,0.89,YACC,0,ZACC,0.12,XSHOCK,0.48,YSHOCK,0.23,ZSHOCK,0.51,Position,standing
Time,238,XACC,0.74,YACC,0.33,ZACC,0.91,XSHOCK,0,YSHOCK,0.54,ZSHOCK,0.9,Position,standing
Time,239,XACC,0.97,YACC,0.19,ZACC,0.8,XSHOCK,0.78,YSHOCK,0.31,ZSHOCK,0.44,Position,standing
Time,240,XACC,0.4,YACC,0.87,ZACC,0.99,XSHOCK,0.25,YSHOCK,0.83,ZSHOCK,0.38,Position,standing

The php read it in and I get an echo of this on one line Time,0,XACC,0.41,YACC,0.67,ZACC,0.34,XSHOCK,0,YSHOCK,0.69,ZSHOCK,0.24,Position,standing

It is changing the time values for some reason. This does not make sense to me.
[php]

<?php $q = $_REQUEST['q']; $devices = file_get_contents("devices.txt"); $dparts = explode("\n", $devices); $string = ""; for($i = 0; $i < count($dparts); $i++) { $typelist = explode(',', $dparts[$i]); if($typelist[0] == $q) { for($j = 1; $j < count($typelist); $j++) { //$string = $string.$typelist[$j]; //$string = $string.","; $readfile = $typelist[0]."_".$typelist[$j].".txt"; $readfile = preg_replace('/\s+/', '', $readfile); $file = file($readfile); if(count($file) >= 5) { for($k = count($file) - 5; $k < count($file); $k++) { echo $file[$i]; //if($k < count($file) - 1) //{ // $string = $string."("; //} } } else { for($k = 0 ; $k < count($file); $k++) { //$string = $string.$file[$i]; //if($k < count($file) - 1) //{ // $string = $string."("; //} } } //if($j != count($typelist)-1) //{ // $string = $string.":"; //} } } } //$string = preg_replace('/\s+/', '', $string); //echo $string; ?>

[/php]

What are you trying to do with the data? I see it being read, but its not doing anything that I can see.

As for the echo issue, remember, you’re dealing with a rather large array. Anything that needs to be pulled out has to be put into a other array, then read outside of the original loop. you can also look through the array functions on php.net.

Sponsor our Newsletter | Privacy Policy | Terms of Service