0

I would like to convert my rpt file to array. The file is divided with commas. Of course that's easy part. The second thing I need to convert it into multidimensional array, which probably is also easy but I got stuck in it. I need to make it that each line of the file will be next row.
I'm looking in my head but I don't know how to solve it.
I hope you'll help me!

enter image description here

enter image description here

10
  • did you try the explode function of php? Commented Jul 4, 2016 at 13:35
  • Yes I did it, but I still have problem with dividing my file that each line will be other row. Commented Jul 4, 2016 at 13:40
  • can you give a sample output of your file? I mean to say the string which you are explode. Commented Jul 4, 2016 at 13:45
  • By now I have something like this: $contents = file_get_contents($path); $pollfields = explode(',', $contents); echo '<pre>'; print_r($pollfields); echo '</pre>'; Commented Jul 4, 2016 at 13:46
  • I want to know the string. You are given all php codes. I need the value of $contents. Commented Jul 4, 2016 at 13:57

1 Answer 1

1
$contents = file($path);
foreach($contents as &$row){
  $row = explode(",",$row);
}

file() reads the file into an array, one line is one array element.

Sign up to request clarification or add additional context in comments.

4 Comments

It's not what I am looking for could you look at the topic again? Thanks for your reply!
This is exactly what you said you want.
Not exactly, because now I have array with rows of the file and I also need to list the column of the rows like in picture above.
Okay I've solved it out, with your code but a little bit editing it. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.