Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8485979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:48:22+00:00 2026-06-10T20:48:22+00:00

Ok, here’s the thing. if (!$fp=fopen($file,r)) echo The file could not be opened.<br/>; while

  • 0

Ok, here’s the thing.

if (!$fp=fopen($file,"r")) echo "The file could not be opened.<br/>";  
            while (( $data = fgetcsv ( $fp , 1000 , ',')) !== FALSE ) {
                // here, var_dump($data); shows the correct array
                $i = 0; 
                foreach ($data as $i=>$row ) {  
                   $matrix=explode( ',', $row);
                   // $matrix recieves only the first field of the csv line
                   // seems like I'm getting a field on each foreach iteration
                   // shouldn't I get the whole line each time?
                } //end foreach
            } //end while

I don’t really see the problem here.
By the way, this code works on my local machine, and doesn’t work on my server. Both are linux, and php versions are the same.

Any thoughts? Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:48:23+00:00Added an answer on June 10, 2026 at 8:48 pm

    fgetscv() returns each row as an array. So your problem is this:

    $data is a row, which is already an array. Each iteration in the while() loop will return a row. There is no need for an explode.

    $allRowsAsArray = array();
    if (!$fp=fopen($file,"r")) echo "The file could not be opened.<br/>";  
    while (( $data = fgetcsv ( $fp , 1000 , ',')) !== FALSE ) 
    {
        $allRowsAsArray[] = $data;
    }
    print_r($allRowsAsArray); //Will return your entire csv as an array of rows, each row as an array.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the code: create table `team`.`User`( `UserID` bigint NOT NULL AUTO_INCREMENT , `Username`
Here is what I am currently doing. PHP echo's out the recent post in
Here is my SQL script CREATE TABLE tracks( track_id int NOT NULL AUTO_INCREMENT, account_id
here is my php code $titikPetaInti = array(); while($row = mysql_fetch_assoc($hasil2)) { $titikPetaInti[] =
Here's what I'm doing. I want to upload multipart file via Ajax to my
here is example data: 10914_Excel Short Summary.xls F:\MassHunter\DATA\10921_PAIN\QuantResults\10921_PAIn.batch.bin 10918_Excel Short Summary.xls 10923_Excel Short Summary.xls
Here is my text file forms. S1,F2 title including several white spaces (abbr) single,Here<->There,reply
Here's a coding problem for those that like this kind of thing. Let's see
Here's an interesting problem. On a recently installed Server 2008 64bit I opened IE
Here is an object that I'd like to use with ng-repeat, but it's not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.