以下php代码:
<?php
$fopen = fopen("tasklistout.csv","r");
while(!feof($fopen))
{
$line = fgets($fopen);
echo "\r\n\t<tr>";
$piece_array = preg_split("/[\s,]+/",$line);
for ($forvar = 1; $forvar <= 5; $forvar++)
{
$array_index = $forvar - 1;
echo "\r\n\t\t<td>" . $piece_array[$array_index] . "</td>";
}
echo "\r\n\t</tr>\r\n";
}
fclose($fopen);
?>
产生以下错误:(在 4 个不同的情况下)
注意:未定义的偏移量:第 33 行 file.php 中的 1
在以下 HTML 文档中:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Lab_11-Objective_01--Tables</title>
<meta name="description" content="HTML 'table' element usage for Lab 11 Objective 01">
<meta name="author" content="Charles E Lentz">
<link rel="stylesheet" href="stylesheet.css">
</head>
<body>
<table>
<tr>
<th>Image Name</th>
<th>PID</th>
<th>Session Name</th>
<th>Session#</th>
<th>Mem Usage</th>
</tr>
<?php
$fopen = fopen("tasklistout.csv","r");
while(!feof($fopen))
{
$line = fgets($fopen);
echo "\r\n\t<tr>";
$piece_array = preg_split("/[\s,]+/",$line);
for ($forvar = 1; $forvar <= 5; $forvar++)
{
$array_index = $forvar - 1;
echo "\r\n\t\t<td>" . $piece_array[$array_index] . "</td>";
}
echo "\r\n\t</tr>\r\n";
}
fclose($fopen);
?>
</table>
</body>
</html>
如何修复此错误?