PHP fgets() to array -


i want first line of foo.csv array.

foo.csv:

i, like, chocolate and, also, milk 

i tried

//$foo foo.csv $file = fopen($foo, "r") //first attempt $fgetsfile = fgets($file) //other way $streamlinefile = stream_get_line($file, 10000, "\n"); fclose($file)  var_dump($fgetsfile) // (string) "i", "like", "chocolate" var_dump($streamlinefile) // (array) [0] => (string) "i", "like", "chocolate" 

i end array this:

array([0] => "i", [1] => "like", [2] => "chocolate) 

you can accomplish more using fgetcsv(). take @ the documentation , corresponding example, maybe use (tested):

if(($file = fopen($foo, "r")) !== false){     if(($data = fgetcsv($file)) !== false){         var_dump($data);     } }  fclose($file); 

Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -