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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:33:35+00:00 2026-06-17T04:33:35+00:00

I am trying to get fgetcsv() to read a comma separated value file. Ordinarily

  • 0

I am trying to get fgetcsv() to read a comma separated value file. Ordinarily this works as expected, but I’ve encountered a file that has some columns being split into new data lines instead of being treated as one.

Here is an example of a lines giving me trouble:
pastie.org/5664800

The column that is creating the problem is the one with the multiple lines that make up the description.

fgetcsv ends the first read when it reaches the following line:

- Length/Width/Height: 3.75\""x2.4\""x2.4\"" (95.25X60.96x60.96) 

So for instance, if I have the code:

ini_set('auto_detect_line_endings', true);

while ($row = fgetcsv($filepointer, 5000, ',', '"') {
    echo '<pre>'; var_dump($row); echo '</pre><br />';
}

I get one mostly complete row of data that ends in “Length/Width/Height: 3.75\"x2.4\""x2.4\"" (95.25X60.96x60.96)” and then every newline after that is treated as its own row all the way down to the end.

Any idea what’s going on here?

  • 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-17T04:33:36+00:00Added an answer on June 17, 2026 at 4:33 am

    The problem is that your data contains the character sequence \"". From the context, it’s clear that this is supposed to represent the literal substring \"; that is, the blackslash is supposed to be a literal backslash, while the double quote has been escaped by doubling it.

    By default, however, fgetcsv() treats the backslash as an escape character, so it parses the characters \" as a backslash-escaped literal double quote, and then assumes that the second " ends the double-quoted string.

    The fix is simple, as long as you’re using PHP 5.3.0 or later: just tell fgetcsv() not to treat the backslash as an escape character by passing some other character as the fifth parameter to it. Apparently, passing null or false or '' won’t work to disable the escape character entirely, but passing '"' (i.e. the same value as the quote character) does:

    while ( $row = fgetcsv( $filepointer, 0, ',', '"', '"' ) ) {
        var_export( $row );
        echo "\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying get url contents with file_get_contents(), its works in my localhost server, but
I am trying get date of call but it's returning value of 1.1.1970(I think
Trying to get this expression to work, can someone look at it and tell
I'm trying get some licensing code from AndroidPit.com working, but I get Unable to
I am trying get the html within .event_recur. $(.entry).each(function(){ alert($(this).find(.event_recur).html()); }); <div class=entry> <p
I'm trying get cross compiling between 2.7.7 and 2.8.0. The package is included, this
Hello everyone I been trying get php uploader working but having a lot of
Trying to get two different counts in one query. To do this I am
Trying to get all articles, with unique titles (distinct(title)), that have a body of
I'm trying get value of var by its name: var1='Hello' var2 = getTextFromFirstTextBox() //text

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.