CSV to JSON with PHP?

前端 未结 6 1443
遥遥无期
遥遥无期 2020-12-31 13:48

I need to convert a CSV file to JSON on the server using PHP. I am using this script which works:

function csvToJSON($csv)          


        
6条回答
  •  星月不相逢
    2020-12-31 14:13

    You could probably reduce the overhead by removing all the spaces and \n's. But that's in your note.

    You could increase the performance by skipping the preg_replace and passing a boolean that would turn it on and off.

    Other than that, the variable unrolling of your var[1-10] actually is good, as long as there are always ten varaibles.

    The explode and the foreach approach are just fine.

提交回复
热议问题