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

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -