我想知道如果任何人都可以給我一點幫助我有一個PHP腳本,它給我這個錯誤:我該如何解決這個「注意:未定義偏移:在第14行」?
注意:未定義抵消:8 XXXX在線/ XXXX/xx.php 14
這裏是我有的代碼:
<?php
// Opens the file "april" in read mode only
$fileLog = fopen("april.txt", "r");
// Variable to count the total bytes used during the month
$totalBytes = 0;
// While not the end of file get and echo the data line by line
while (!feof($fileLog)) {
$line = fgets($fileLog, 1024);
// Explodes the data with a space
$details = explode(' ', $line);
// Adds all the bytes and stores them in $totalBytes
$totalBytes = $totalBytes +(int)$details[8]; // line 14
}
echo "<h3>April Statistics</h3>";
// echoes the total bytes
echo "<p>The TOTAL bandwidth consumed used: 8.43MB ($totalBytes Bytes)</p>";
fclose($fileLog);
?>
誰能告訴我如何解決這個問題或給我一個例子。 任何幫助將深表謝意謝謝。
確定這裏是該文件的內容的一個示例:
103.239.234.105 - [2007-04-01〇點42分21秒] 「GET文章/ learn_PHP_basics HTTP/1.0」 200 12729「的Mozilla/4.0 「
207.3.35.52 - [2007-04-01 1點24分42秒] 」GET的index.php HTTP/1.0「 200 11411 」的Mozilla/4.0「
和IM添加由消耗的總帶寬該月份請求的文件。
哪條線是線14日前加入呢? – Bojangles
您至少有一行包含少於九個「單詞」,這會導致'$ details'具有少於九個元素(偏移量8將是第九個元素)。 –