Php file function does not work on long csv file












1















I am using:



$csv = file($filePathTest);


where $filePathTest is path to this csv:



policyID,statecode,county,eq_site_limit,hu_site_limit,fl_site_limit,fr_site_limit,tiv_2011,tiv_2012,eq_site_deductible,hu_site_deductible,fl_site_deductible,fr_site_deductible,point_latitude,point_longitude,line,construction,point_granularity
119736,FL,CLAY COUNTY,498960,498960,498960,498960,498960,792148.9,0,9979.2,0,0,30.102261,-81.711777,Residential,Masonry,1
448094,FL,CLAY COUNTY,1322376.3,1322376.3,1322376.3,1322376.3,1322376.3,1438163.57,0,0,0,0,30.063936,-81.707664,Residential,Masonry,3
206893,FL,CLAY COUNTY,190724.4,190724.4,190724.4,190724.4,190724.4,192476.78,0,0,0,0,30.089579,-81.700455,Residential,Wood,1


and the result of file($filePathTest) is correctly:



(array) [4 elements]
0: (string) "policyID,statecode,county,eq_site_limit,hu_site_limit,fl_site_limit,fr_site_limit,tiv_2011,tiv_2012,eq_site_deductible,hu_site_deductible,fl_site_deductible,fr_site_deductible,point_latitude,point_longitude,line,construction,point_granularity
"
1: (string) "119736,FL,CLAY COUNTY,498960,498960,498960,498960,498960,792148.9,0,9979.2,0,0,30.102261,-81.711777,Residential,Masonry,1
"
2: (string) "448094,FL,CLAY COUNTY,1322376.3,1322376.3,1322376.3,1322376.3,1322376.3,1438163.57,0,0,0,0,30.063936,-81.707664,Residential,Masonry,3
"
3: (string) "206893,FL,CLAY COUNTY,190724.4,190724.4,190724.4,190724.4,190724.4,192476.78,0,0,0,0,30.089579,-81.700455,Residential,Wood,1"


The problem is, when I use a big csv file of 36000 rows the function file($filePathTest) return not correctly an array with a single element that include all the csv. I cannot understand why!



 (array) [1 element]
0: (string)"All the csv file inside here "









share|improve this question


















  • 1





    Wouldn't reading it line by line be a better approach with large files - stackoverflow.com/questions/2805427/…

    – Nigel Ren
    Nov 24 '18 at 15:09











  • I have the same issue also line by line

    – Isabella
    Nov 24 '18 at 15:37











  • Using fgetcsv() does it try and have all columns in the first row?

    – Nigel Ren
    Nov 24 '18 at 15:40











  • Yes with fgetcsv is all in one raw!!

    – Isabella
    Nov 24 '18 at 16:36











  • This is really strange

    – Isabella
    Nov 24 '18 at 16:54
















1















I am using:



$csv = file($filePathTest);


where $filePathTest is path to this csv:



policyID,statecode,county,eq_site_limit,hu_site_limit,fl_site_limit,fr_site_limit,tiv_2011,tiv_2012,eq_site_deductible,hu_site_deductible,fl_site_deductible,fr_site_deductible,point_latitude,point_longitude,line,construction,point_granularity
119736,FL,CLAY COUNTY,498960,498960,498960,498960,498960,792148.9,0,9979.2,0,0,30.102261,-81.711777,Residential,Masonry,1
448094,FL,CLAY COUNTY,1322376.3,1322376.3,1322376.3,1322376.3,1322376.3,1438163.57,0,0,0,0,30.063936,-81.707664,Residential,Masonry,3
206893,FL,CLAY COUNTY,190724.4,190724.4,190724.4,190724.4,190724.4,192476.78,0,0,0,0,30.089579,-81.700455,Residential,Wood,1


and the result of file($filePathTest) is correctly:



(array) [4 elements]
0: (string) "policyID,statecode,county,eq_site_limit,hu_site_limit,fl_site_limit,fr_site_limit,tiv_2011,tiv_2012,eq_site_deductible,hu_site_deductible,fl_site_deductible,fr_site_deductible,point_latitude,point_longitude,line,construction,point_granularity
"
1: (string) "119736,FL,CLAY COUNTY,498960,498960,498960,498960,498960,792148.9,0,9979.2,0,0,30.102261,-81.711777,Residential,Masonry,1
"
2: (string) "448094,FL,CLAY COUNTY,1322376.3,1322376.3,1322376.3,1322376.3,1322376.3,1438163.57,0,0,0,0,30.063936,-81.707664,Residential,Masonry,3
"
3: (string) "206893,FL,CLAY COUNTY,190724.4,190724.4,190724.4,190724.4,190724.4,192476.78,0,0,0,0,30.089579,-81.700455,Residential,Wood,1"


The problem is, when I use a big csv file of 36000 rows the function file($filePathTest) return not correctly an array with a single element that include all the csv. I cannot understand why!



 (array) [1 element]
0: (string)"All the csv file inside here "









share|improve this question


















  • 1





    Wouldn't reading it line by line be a better approach with large files - stackoverflow.com/questions/2805427/…

    – Nigel Ren
    Nov 24 '18 at 15:09











  • I have the same issue also line by line

    – Isabella
    Nov 24 '18 at 15:37











  • Using fgetcsv() does it try and have all columns in the first row?

    – Nigel Ren
    Nov 24 '18 at 15:40











  • Yes with fgetcsv is all in one raw!!

    – Isabella
    Nov 24 '18 at 16:36











  • This is really strange

    – Isabella
    Nov 24 '18 at 16:54














1












1








1








I am using:



$csv = file($filePathTest);


where $filePathTest is path to this csv:



policyID,statecode,county,eq_site_limit,hu_site_limit,fl_site_limit,fr_site_limit,tiv_2011,tiv_2012,eq_site_deductible,hu_site_deductible,fl_site_deductible,fr_site_deductible,point_latitude,point_longitude,line,construction,point_granularity
119736,FL,CLAY COUNTY,498960,498960,498960,498960,498960,792148.9,0,9979.2,0,0,30.102261,-81.711777,Residential,Masonry,1
448094,FL,CLAY COUNTY,1322376.3,1322376.3,1322376.3,1322376.3,1322376.3,1438163.57,0,0,0,0,30.063936,-81.707664,Residential,Masonry,3
206893,FL,CLAY COUNTY,190724.4,190724.4,190724.4,190724.4,190724.4,192476.78,0,0,0,0,30.089579,-81.700455,Residential,Wood,1


and the result of file($filePathTest) is correctly:



(array) [4 elements]
0: (string) "policyID,statecode,county,eq_site_limit,hu_site_limit,fl_site_limit,fr_site_limit,tiv_2011,tiv_2012,eq_site_deductible,hu_site_deductible,fl_site_deductible,fr_site_deductible,point_latitude,point_longitude,line,construction,point_granularity
"
1: (string) "119736,FL,CLAY COUNTY,498960,498960,498960,498960,498960,792148.9,0,9979.2,0,0,30.102261,-81.711777,Residential,Masonry,1
"
2: (string) "448094,FL,CLAY COUNTY,1322376.3,1322376.3,1322376.3,1322376.3,1322376.3,1438163.57,0,0,0,0,30.063936,-81.707664,Residential,Masonry,3
"
3: (string) "206893,FL,CLAY COUNTY,190724.4,190724.4,190724.4,190724.4,190724.4,192476.78,0,0,0,0,30.089579,-81.700455,Residential,Wood,1"


The problem is, when I use a big csv file of 36000 rows the function file($filePathTest) return not correctly an array with a single element that include all the csv. I cannot understand why!



 (array) [1 element]
0: (string)"All the csv file inside here "









share|improve this question














I am using:



$csv = file($filePathTest);


where $filePathTest is path to this csv:



policyID,statecode,county,eq_site_limit,hu_site_limit,fl_site_limit,fr_site_limit,tiv_2011,tiv_2012,eq_site_deductible,hu_site_deductible,fl_site_deductible,fr_site_deductible,point_latitude,point_longitude,line,construction,point_granularity
119736,FL,CLAY COUNTY,498960,498960,498960,498960,498960,792148.9,0,9979.2,0,0,30.102261,-81.711777,Residential,Masonry,1
448094,FL,CLAY COUNTY,1322376.3,1322376.3,1322376.3,1322376.3,1322376.3,1438163.57,0,0,0,0,30.063936,-81.707664,Residential,Masonry,3
206893,FL,CLAY COUNTY,190724.4,190724.4,190724.4,190724.4,190724.4,192476.78,0,0,0,0,30.089579,-81.700455,Residential,Wood,1


and the result of file($filePathTest) is correctly:



(array) [4 elements]
0: (string) "policyID,statecode,county,eq_site_limit,hu_site_limit,fl_site_limit,fr_site_limit,tiv_2011,tiv_2012,eq_site_deductible,hu_site_deductible,fl_site_deductible,fr_site_deductible,point_latitude,point_longitude,line,construction,point_granularity
"
1: (string) "119736,FL,CLAY COUNTY,498960,498960,498960,498960,498960,792148.9,0,9979.2,0,0,30.102261,-81.711777,Residential,Masonry,1
"
2: (string) "448094,FL,CLAY COUNTY,1322376.3,1322376.3,1322376.3,1322376.3,1322376.3,1438163.57,0,0,0,0,30.063936,-81.707664,Residential,Masonry,3
"
3: (string) "206893,FL,CLAY COUNTY,190724.4,190724.4,190724.4,190724.4,190724.4,192476.78,0,0,0,0,30.089579,-81.700455,Residential,Wood,1"


The problem is, when I use a big csv file of 36000 rows the function file($filePathTest) return not correctly an array with a single element that include all the csv. I cannot understand why!



 (array) [1 element]
0: (string)"All the csv file inside here "






php csv






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 24 '18 at 14:39









IsabellaIsabella

102




102








  • 1





    Wouldn't reading it line by line be a better approach with large files - stackoverflow.com/questions/2805427/…

    – Nigel Ren
    Nov 24 '18 at 15:09











  • I have the same issue also line by line

    – Isabella
    Nov 24 '18 at 15:37











  • Using fgetcsv() does it try and have all columns in the first row?

    – Nigel Ren
    Nov 24 '18 at 15:40











  • Yes with fgetcsv is all in one raw!!

    – Isabella
    Nov 24 '18 at 16:36











  • This is really strange

    – Isabella
    Nov 24 '18 at 16:54














  • 1





    Wouldn't reading it line by line be a better approach with large files - stackoverflow.com/questions/2805427/…

    – Nigel Ren
    Nov 24 '18 at 15:09











  • I have the same issue also line by line

    – Isabella
    Nov 24 '18 at 15:37











  • Using fgetcsv() does it try and have all columns in the first row?

    – Nigel Ren
    Nov 24 '18 at 15:40











  • Yes with fgetcsv is all in one raw!!

    – Isabella
    Nov 24 '18 at 16:36











  • This is really strange

    – Isabella
    Nov 24 '18 at 16:54








1




1





Wouldn't reading it line by line be a better approach with large files - stackoverflow.com/questions/2805427/…

– Nigel Ren
Nov 24 '18 at 15:09





Wouldn't reading it line by line be a better approach with large files - stackoverflow.com/questions/2805427/…

– Nigel Ren
Nov 24 '18 at 15:09













I have the same issue also line by line

– Isabella
Nov 24 '18 at 15:37





I have the same issue also line by line

– Isabella
Nov 24 '18 at 15:37













Using fgetcsv() does it try and have all columns in the first row?

– Nigel Ren
Nov 24 '18 at 15:40





Using fgetcsv() does it try and have all columns in the first row?

– Nigel Ren
Nov 24 '18 at 15:40













Yes with fgetcsv is all in one raw!!

– Isabella
Nov 24 '18 at 16:36





Yes with fgetcsv is all in one raw!!

– Isabella
Nov 24 '18 at 16:36













This is really strange

– Isabella
Nov 24 '18 at 16:54





This is really strange

– Isabella
Nov 24 '18 at 16:54












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53459253%2fphp-file-function-does-not-work-on-long-csv-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53459253%2fphp-file-function-does-not-work-on-long-csv-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Futebolista

Feedback on college project

Albești (Vaslui)