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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:42:56+00:00 2026-05-27T02:42:56+00:00

I am trying to parse a csv file where my data is given in

  • 0

I am trying to parse a csv file where my data is given in a format like :

"Total","Shazam (DE)","Total",,"215,611","538","£935.97","£60.77"

Now if I give fgetcsv() like the one below :

$values = fgetcsv($f,8098);

It returns me an array as :

array(9) {
  [0]=>
    string(15) ""Total""
  [1]=>
    string(27) ""Shazam (DE)""
  [2]=>
    string(15) ""Total""
  [3]=>
    string(1) ""
  [4]=>
    string(9) ""215"
  [5]=>
    string(9) "611""
  [6]=>
    string(11) ""538""
  [7]=>
    string(19) ""£935.97""
  [8]=>
    string(19) ""£60.77"
 "
 }

but now , If I give a if statement like :

 $values = fgetcsv($f,8098);
 if ($values[0] == "Total")
   echo "Hello";

it’s not echoing out anything , why the condition isn’t satisfied ? Is it something to do with the enclosing quotes ?

I even tried escaping quotes e.g .

 if ($values[0] == '\"Total\"')
   echo "Hello";

but to no use.

Do , I need to change any .ini settings for this ? Please help me.

EDIT : I tried doing var_dump , and it did show my values containg quotes :

 array(9) {
  [0]=>
   string(15) ""Total""
 [1]=>
   string(27) ""Shazam (DE)""
 [2]=>
   string(15) ""Total""
 [3]=>
   string(1) ""
 ...
}

but even

$values[0] == "\"Total\""

didn’t work . What should be the right comparator ?

UPDATE : After few hours of aimless trial and error , finally found something annoying , but it fixed my problem .

Initially , when I tried to open my csv file , it opened a notepad with ÿþD”” as it’s content . What , I did is , copied the entire filecontent and created a new csv file with the same name , and to my surprise , it worked .

The old file was opening nicely in MS-EXCEL / NOTEPAD , but in excel , each line was being displayed inside one single cell .

My question is , what was the issue with the .csv fromat ? Has anyone coome across with such problem before?

  • 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-27T02:42:57+00:00Added an answer on May 27, 2026 at 2:42 am

    I think you need to define a text qualifier, this is called enclosure in fgetcsv.
    eg:

    $values = fgetcsv($f,8098,'"'); 
    // the last part is: singlequote doublequote singlequote,
    // you could also use an escape "\"" 
    

    This is to tell the parser that it shouldn’t take the comma inside the text area.

    You should be able to do:

    $values[0] == '"Total"'
    

    UPDATE:

    You problem with the file opening oddly, is probably related to
    the files encoding, by creating a new file, you created it with a new
    encoding maybe ANSI/UTF-8/Unicode something the original file wasnt, and then copied the content in there, so now it was saved in that format instead.. im not sure why this would give you the problems you are experiencing, but im assume the parser somehow cant handle the wrong encoding.

    try opening notepad and notice when you click save as, you can choose encoding in the buttom, try with a few different files with different encoding if you want to make sure that was it?

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

Sidebar

Related Questions

I am trying to parse a CSV file containing some data, mostly numeral but
Trying to parse a csv file that has all the data wrapped in double
I'm trying to parse a .csv file with OpenCSV in NetBeans 6.0.1. My file
I'm trying to parse a large csv file and perform some operations on that
I am trying to parse a .csv file into a mysql database, and it's
I trying to parse a data in a MySql Format, I ran across SimpleDateFormat
Now I am trying to import contact details from a csv file. In csv
Trying to use filegetcsv to parse a CSV file and do stuff with it,
I'm trying to parse a CSV file using Python's csv module (specifically, the DictReader
I am trying to parse a CSV file generated from an Excel spreadsheet. Here

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.