ATM im trying to learn working with CSV files and importing goes fine. Heres the code for it:
<?php
$list = array
(
"josef,durba,Bos,EN",
"sjaqeline,toulors,paris,FR",
);
$file = fopen("c://temp.csv","w");
foreach ($list as $line)
{
fputcsv($file,split(',',$line));
}
fclose($file);
?>
Now i want to read this file with the following code:
$bestand = fopen("c://temp.csv", "r");
while (!feof($bestand)) {
$csvArray = fgetcsv($bestand, 1024);
foreach ($csvArray as $key => $value) {
print "key is: " . $key . " value is: " . $value . "<br>";
}
}
fclose($bestand);
?>however here lies my problem. When i execute the script it prints the following:key is: 0 value is: josef
key is: 1 value is: durba
key is: 2 value is: Bos
key is: 3 value is: EN
key is: 0 value is: sjaqeline
key is: 1 value is: toulors
key is: 2 value is: paris
key is: 3 value is: FR
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\CSVproject\index.php on line 71
And im really clueless here i have NO idea how to get rid of the last error. It seems like everything is going fine but the error keeps popping up. So anyone have any ideas and can help me? Its really killing me!
Anyhow thanks in advance.
Edited by Jaan, 14 July 2010 - 09:19 PM.
Please use code tags when you are posting your codes!


Sign In
Create Account


Back to top










