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

  • Home
  • SEARCH
  • 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 6098737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:11:33+00:00 2026-05-23T13:11:33+00:00

I have a CSV file and using fgetcsv I can happily generate each line

  • 0

I have a CSV file and using fgetcsv I can happily generate each line as an array.

Pipes indicate structure and cell division, commas in the below are commas that are part of the input and need to be preserved.

abc,456|5hs6|dfdsf,56
abc,456|5hs6|dfdsf,56
abc,456|5hs6|dfdsf,56
abc,456|5hs6|dfdsf,56

Given that commas would be used in the data as shown, it would be better to separate using pipes.

Array(
[0] => abc,456|5hs6|dfdsf,56
[1] => abc,456|5hs6|dfdsf,56
[2] => abc,456|5hs6|dfdsf,56
[3] => abc,456|5hs6|dfdsf,56
)
  • 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-05-23T13:11:33+00:00Added an answer on May 23, 2026 at 1:11 pm

    If your CSV file is different from what you want to have in the array afterwards, e.g. the CSV is something like

    "1","2","3","4","5","6"
    "1","2","3","4","5","6"
    …
    

    or anything else that actually requires parsing it with fgetcsv then use

    $result = array();
    while (($line = fgetscsv($handler) !== false) {
      $result[] = implode(',', $line);
    }
    

    If your CSV file already contains what you want to have in the array afterwards, e.g.

    1,2,3,4,5,6
    1,2,3,4,5,6
    …
    

    then you dont need to parse it as CSV (which is slower), but can do

    $result = array();
    while (($line = fgets($handler) !== false) {
      $result[] = $line;
    }
    

    or just use $array = file('filename.csv')

    The difference is, that a) it is implicitly assumed, that the csv-source use , as separator, because we just take them as they are noted in the file, and b) it will not remove any enclosures (You may enclose a value in "to avoid a , within it is treated as a csv-delimiter), but that seems just useful here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CSV of file of data that I can load in R
How can we validate a CSV file ? I have an CSV file of
I have CSV data loaded into a multidimensional array. In this way each row
I have a record that I write out to a CSV file using FileHelpers.
I am trying to process a csv file using awk. I have five rows
Problem with german umlauts in generated CSV file using Grails Hi, I have a
Using jmeter, I have a variable passed from CSV file (using CSV Data Set
How can I convert a .csv file into .dbf file using a python script?
I have a .csv file that is frequently updated (about 20 to 30 times
I have a CSV file that holds about 200,000 - 300,000 records. Most of

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.