簡單修復「通知」:只需檢查該索引是否存在。所以這一段代碼:
$commentator_name = $comment_array[$i];
$commentator_comment = $comment_array[$i+1];
更改爲:
$commentator_name = $commentator_comment = '';
if (isset($comment_array[$i])) {
$commentator_name = $comment_array[$i];
}
if (isset($comment_array[$i+1])) {
$commentator_comment = $comment_array[$i+1];
}
當我寫了這個代碼,我在一箇舊的筆記本電腦,我不得不在服務器上運行 工作,因爲WAMP等沒有工作,我沒有得到通知 然後。
無論舊服務器設置如何,它都可能是新服務器設置&之間的錯誤報告級別。這意味着新的服務器被設置爲報告PHP通知,但舊的服務器沒有。
要調整錯誤報告設置,您可以先進入php.ini
並查找error_reporting
行。在Ubuntu 12.04 &其他Linux安裝的php.ini
位於:
/etc/php5/apache2/php.ini
通常是線正好被設置爲E_ALL
這樣的:
error_reporting = E_ALL
要禁用通知,您可以調整該行這樣的:
error_reporting = E_ALL & ~E_NOTICE
而且你甚至可以添加更多的選項來禁用,如下所示將它們鏈接到該行的末尾:
error_reporting = E_ALL & ~E_NOTICE & ~E_WARNING
PHP錯誤級別常量的完整列表應該在php.ini
文件中。這裏是一個副本,如果是在一個典型的php.ini
文件的註釋所示的那些:
; Error Level Constants:
; E_ALL - All errors and warnings (includes E_STRICT as of PHP 6.0.0)
; E_ERROR - fatal run-time errors
; E_RECOVERABLE_ERROR - almost fatal run-time errors
; E_WARNING - run-time warnings (non-fatal errors)
; E_PARSE - compile-time parse errors
; E_NOTICE - run-time notices (these are warnings which often result
; from a bug in your code, but it's possible that it was
; intentional (e.g., using an uninitialized variable and
; relying on the fact it's automatically initialized to an
; empty string)
; E_STRICT - run-time notices, enable to have PHP suggest changes
; to your code which will ensure the best interoperability
; and forward compatibility of your code
; E_CORE_ERROR - fatal errors that occur during PHP's initial startup
; E_CORE_WARNING - warnings (non-fatal errors) that occur during PHP's
; initial startup
; E_COMPILE_ERROR - fatal compile-time errors
; E_COMPILE_WARNING - compile-time warnings (non-fatal errors)
; E_USER_ERROR - user-generated error message
; E_USER_WARNING - user-generated warning message
; E_USER_NOTICE - user-generated notice message
; E_DEPRECATED - warn about code that will not work in future versions
; of PHP
; E_USER_DEPRECATED - user-generated deprecation warnings
請問你comments.txt樣子? – Xatenev