【发布时间】:2015-08-01 13:09:22
【问题描述】:
我过去一直在使用这个脚本并且没问题。我将 txt 文件转换为 csv 并得到了一些未定义的错误。
function Importcsv($filename) { $row = 0;
$col = 0;
$handle = @fopen($filename, "r");
if ($handle)
{
while (($row = fgetcsv($handle, 4096)) !== false)
{
if (empty($fields))
{
$fields = $row;
continue;
}
foreach ($row as $k=>$value)
{
$results[$col][$fields[$k]] = $value;
}
$col++;
unset($row);
}
if (!feof($handle))
{
echo "Error: unexpected fgets() failn";
}
fclose($handle);
}
return $results; }
$filename = "tm_data.csv";
$csvArray = Importcsv($filename);
foreach ($csvArray as $row)
{
echo $row['CITY'];
}
如果您之前有任何想法或发现类似问题,请告诉我。
请查看几个错误行 注意:未定义的偏移量:/Applications/XAMPP/xamppfiles/htdocs/tm_marketing/index.php 第 20 行中的 386
注意:未定义的偏移量:第 20 行 /Applications/XAMPP/xamppfiles/htdocs/tm_marketing/index.php 中的 387
注意:未定义的偏移量:第 20 行 /Applications/XAMPP/xamppfiles/htdocs/tm_marketing/index.php 中的 388
注意:未定义的偏移量:第 20 行 /Applications/XAMPP/xamppfiles/htdocs/tm_marketing/index.php 中的 389
注意:未定义的偏移量:/Applications/XAMPP/xamppfiles/htdocs/tm_marketing/index.php 第 20 行中的 390
谢谢,
【问题讨论】:
-
发布完整的错误消息,没有它我们无法帮助您。
-
请看下面几行错误信息:注意:未定义的偏移量:386 in /Applications/XAMPP/xamppfiles/htdocs/tm_marketing/index.php on line 20 注意:未定义的偏移量:387 in /Applications /XAMPP/xamppfiles/htdocs/tm_marketing/index.php 在第 20 行 注意:未定义的偏移量:388 在 /Applications/XAMPP/xamppfiles/htdocs/tm_marketing/index.php 在第 20 行 注意:未定义的偏移量:389 在 /Applications/XAMPP /xamppfiles/htdocs/tm_marketing/index.php 第 20 行 注意:未定义的偏移量:/Applications/XAMPP/xamppfiles/htdocs/tm_marketing/index.php 第 20 行中的 390
-
@user4773611 在您的问题中包含错误。您可以通过编辑您的问题来做到这一点。