kimjessen Posted January 24, 2015 Share Posted January 24, 2015 Hello yes so I let myself be carried away, and then came a new small challenge. In the graph code is the csv file opened and soteret with a "explod" function. and it work fine as long as I only have one column with y data and one with x data. but when I start to get more column's it does not work. I've created a short example below. <?php define("LOG_FILE", "./data/test111/test111-2015-01-17.csv"); $times = array(); $values = array(); $values_test1 = array(); $file_lines = file(LOG_FILE , FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES); foreach($file_lines as $line_num => $line_value) { $line_elements = explode(",", $line_value); $times[] = date($line_elements[0]); $values[] = $line_elements[1]; $values_test1[] = $line_elements[2]; } echo $values[2]; ?> the control echo I make "echo $values[2];" works fine, there is be the expected value. but if I try to "echo $values_test1[2];" so there is nothing. the CSV file looks like this. Date,temp1,temp2 2015-01-23-12-00,54,59 2015-01-23-12-01,54,59 2015-01-23-12-02,54,59 2015-01-23-12-03,54,58 2015-01-23-12-04,54,58 2015-01-23-12-05,54,58 2015-01-23-12-06,54,58 2015-01-23-12-07,54,58 2015-01-23-12-08,54,58 2015-01-23-12-09,54,58 2015-01-23-12-10,54,58 2015-01-23-12-11,53,58 2015-01-23-12-12,53,58 2015-01-23-12-13,53,58 2015-01-23-12-14,53,58 why can I not get the temp2 values into $ values_test1 [] thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/294200-explod-csv-file/ Share on other sites More sharing options...
Solution Jacques1 Posted January 24, 2015 Solution Share Posted January 24, 2015 The code works just fine for me (using the test data you've provided). So what exactly is the problem? Have you inspected the variables with var_dump? What's the content of $file_lines and $line_elements? By the way, PHP can parse CSV files, so no need to mess with file() and explode(). Quote Link to comment https://forums.phpfreaks.com/topic/294200-explod-csv-file/#findComment-1504083 Share on other sites More sharing options...
kimjessen Posted January 24, 2015 Author Share Posted January 24, 2015 Hi It is very odd! I just tried it on another server, my web hotel at one.com And yes there it works. The server I otherwise use a SME server at home. I will try it again when I get home Sunday night. until then, many thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/294200-explod-csv-file/#findComment-1504092 Share on other sites More sharing options...
kimjessen Posted February 8, 2015 Author Share Posted February 8, 2015 Hello excuse my late reply, been busy. Well, better late than never. It works perfectly, and here now the file I work with is and corrupted. after a little adjustment so does the file perfectly. Many thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/294200-explod-csv-file/#findComment-1505201 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.