Jump to content


Photo

CSV To Array


  • Please log in to reply
6 replies to this topic

#1 doublet216

doublet216

    Member

  • Members
  • PipPip
  • 10 posts

Posted 04 March 2013 - 01:00 AM

I am stuck getting a CSV file that I upload into an array in javascript.   So far my file upload gives me.

 

param_name,param_val "name2","value2" "name","value" "name1","value1"

 

I need to just grab the values inside the " ".  So I would need an array to go like

 

array(

[0] name2 => value 2

[1] name => value

[2] name1 => value 1

)

 

I am stuck and can't seem to get it how I need it.   Can anyone help? I have tried replacing and splitting but with no such luck.  Any push in the right direction is appreciated. 

 

 

 

My Excel CSV looks like this

 

param_name | param_val

name 2          | value2

name             | value

name1           | value1



#2 haku

haku

    Advanced Member

  • Staff Alumni
  • 6,177 posts

Posted 04 March 2013 - 01:55 AM

Is the .csv file a single line exactly as you are showing it?

#3 doublet216

doublet216

    Member

  • Members
  • PipPip
  • 10 posts

Posted 04 March 2013 - 10:18 AM

its an excel document with 2 columns and 4 rows.

 

param_name |  param_val

name 2          |  value2

name             |  value

name1           |  value1



#4 haku

haku

    Advanced Member

  • Staff Alumni
  • 6,177 posts

Posted 04 March 2013 - 10:41 AM

Excel files are binary and cannot be parsed as text.

#5 doublet216

doublet216

    Member

  • Members
  • PipPip
  • 10 posts

Posted 04 March 2013 - 10:52 AM

even if .csv



#6 .josh

.josh

    .josh

  • Staff Alumni
  • 14,820 posts

Posted 04 March 2013 - 12:19 PM

If you save as .csv then each row should look like

 

 

value1,value2

 

or 

 

"value1","value2"

 

 

..but you are showing pipes...are you just using pipes in your post or is that what you really have in your file? 

 

in any case...are you sure this is javascript you are talking about?  javascript cannot read files...well, I guess if you have an ActiveX object...is that what you have?  Or are you uploading the file and then using php or some other server-side language to respond w/ the contents (i.e. ajax)?  IOW, how are you opening the file and getting the data to javascript? 



Did I help you? Feeling generous? Donate to me! || Donate to phpfreaks!
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#7 haku

haku

    Advanced Member

  • Staff Alumni
  • 6,177 posts

Posted 04 March 2013 - 06:23 PM

If you save it as a .csv file, it's not an excel file anymore, and we are back to my original question of what the actual text looks like. But that all said, all the questions raised in the last post are relevant.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com