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
Post a Comment