Hey Guys,

I have a text file (new.txt) containing values "100.000 100.000 99.931 99.930 99.932 99.723" - a string of uptime stats. Im wishing to assign each of these values to an array so I can manipulate the date (add them and then devide by 6 to get a 6 month average). Im pretty sure i'll figure out the addition side of things but im struggling to get the array right.

$file = 'array(file_get_contents ('new.txt'))';
Echo "uptime is {$file['1']} <br>";
Echo "uptime is {$file['2']} <br>";
Echo "uptime is {$file['3']} <br>";
Echo $file;
?>

I imagine it's probably just a matter of getting the first line right. Im not quite sure how the " and ' and 's differ. I've used bash a bit and it doesnt seem to follow the same sorta syntax! Any corrections to the above code would be appreciated, and a link to something covering the basics of how the, ", ' characters are interpreted would be good too.

Thanks heaps in advance

Stewart

    if you want an array then use [man]file[/man] instead of [man]file_get_contents[/man]

      The data is all on the same line, I see this on php.about.com

      "The file () PHP function retrieves data from a file and puts it into an array. The array consists of the line number, and the data held in that line starting with 0. If your data isn't separated by new lines this may not return what you expect."

      is there a way around this?

        What you want to do is retrieve the data in full, and the split the data into an array based on the spaces.

        $data = file_get_contents('file.txt');

        $bits = explode(" ", $data);

        $bits[0] now holds the first value

          Write a Reply...