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 8836627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:32:20+00:00 2026-06-14T09:32:20+00:00

I am new at php programming but I have been stuck with this code

  • 0

I am new at php programming but I have been stuck with this code for some time.
I would like to read a .csv file line by line and then save its values in a list of arrays.

$file = fopen('Sub-Companies.csv', 'r');    
while (($line =
fgetcsv($file)) !== FALSE) { 
print_r($line);
list($customer_id[],$company_name[],$department[],$employee[],$country[],$zipcode[],$address[],$city[],
$smth1[], $smth2[], $phone_no1[],$phone_no2[],$email[],$website[],
$customer_no[],$problem1[],$problem2[]) = explode(";",$line);  }
fclose($file); var_dump($customer_id);

The problem is that, although it is read correctly the file, then the explode is not working and the arrays appear to be null.

One thing that I am considering is that some arrays have more “;” than others, so that might be a problem, that is why I have the arrays $problem1 and $problem2, in order to store the values of this arrays.

Any help would be great!

  • 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-14T09:32:22+00:00Added an answer on June 14, 2026 at 9:32 am

    You’re using fgetcsv() in the wrong way.

    We’ve come to this solution while chatting here on StackOverflow.

    <?php
    // Create file data.csv with your data
    $handle = fopen('Sub-Companies.csv', 'r');
    
    $customer_id = array();
    $xyz_array = array();
    // ...
    
    // Better use a specified length (second parameter) instead of 0
    // It slows down the whole process of reading the data!
    while (($line = fgetcsv($handle, 0, ';')) !== FALSE) {
      $customer_id[] = $line[0];
        $xyz_array[] = $line[1];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to VBA but have previous experience with PHP programming logic and
I'm new to PHP programming and have poor knowledge about it, but I want
I am fairly new to PHP, but have applied my previous knowledge of programming,
I'm pretty new to OOP (and also in PHP programming), and I have some
I am new to PHP and programming in general. I have been working on
I am rather new to socket programming but here goes nothing. I have been
Hey I am very new to Web Programming. I have been learning PHP from
I've done a fair bit of mysql php programming but am pretty new to
I'm relatively new to web programming. New to Javascript, PHP, Ajax, etc. I have
As a PHP programmer new to Perl working through 'Programming Perl', I have come

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.