doublet216 Posted March 4, 2013 Share Posted March 4, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/275202-csv-to-array/ Share on other sites More sharing options...
haku Posted March 4, 2013 Share Posted March 4, 2013 Is the .csv file a single line exactly as you are showing it? Quote Link to comment https://forums.phpfreaks.com/topic/275202-csv-to-array/#findComment-1416395 Share on other sites More sharing options...
doublet216 Posted March 4, 2013 Author Share Posted March 4, 2013 its an excel document with 2 columns and 4 rows. param_name | param_val name 2 | value2 name | value name1 | value1 Quote Link to comment https://forums.phpfreaks.com/topic/275202-csv-to-array/#findComment-1416474 Share on other sites More sharing options...
haku Posted March 4, 2013 Share Posted March 4, 2013 Excel files are binary and cannot be parsed as text. Quote Link to comment https://forums.phpfreaks.com/topic/275202-csv-to-array/#findComment-1416477 Share on other sites More sharing options...
doublet216 Posted March 4, 2013 Author Share Posted March 4, 2013 even if .csv Quote Link to comment https://forums.phpfreaks.com/topic/275202-csv-to-array/#findComment-1416480 Share on other sites More sharing options...
.josh Posted March 4, 2013 Share Posted March 4, 2013 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? Quote Link to comment https://forums.phpfreaks.com/topic/275202-csv-to-array/#findComment-1416500 Share on other sites More sharing options...
haku Posted March 4, 2013 Share Posted March 4, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/275202-csv-to-array/#findComment-1416591 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.