<?php
// Dump the games.csv file into an array
$games = fgets('file/games.csv');
// Parse the array
foreach($games as $game)
{
echo "{$game}";
}
?>
Error i get
Warning: fgets() expects parameter 1 to be resource, string given in C:\wamp\www\test\peartest.php on line 3
Call Stack
# Time Memory Function Location
1 0.0004 671880 {main}( ) ..\peartest.php:0
2 0.0004 672008 fgets ( ) ..\peartest.php:3
( ! ) Warning: Invalid argument supplied for foreach() in C:\wamp\www\test\peartest.php on line 5
Call Stack
# Time Memory Function Location
1 0.0004 671880 {main}( ) ..\peartest.php:0
------------------------------
Any solution to it ?????
kakalahori
0
Junior Poster in Training
Recommended Answers
Jump to PostYou need to
fopen
the file first, see the example in the manual.
Jump to PostI think you have to define a variable of type file and pass it as parameter to the fgets():
<?php $file = fopen("file/games.csv","r"); // Dump the games.csv file into an array $games = fgets($file); // Parse the array foreach($games as $game) { echo "{$game}"; } fclose($file); ?> …
Jump to PostWhy not use fgetcsv()?
All 9 Replies
pritaeas
2,194
¯\_(ツ)_/¯
Moderator
Featured Poster
cmps
26
Light Poster
diafol
kakalahori
0
Junior Poster in Training
kakalahori
0
Junior Poster in Training
kakalahori
0
Junior Poster in Training
kakalahori
0
Junior Poster in Training
cmps
26
Light Poster
diafol
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.