-3
我嘗試了許多解決方案,但它確實有幫助。我甚至嘗試開啓short_tags_on,但沒有解決方案。如何解決PHP中的「解析錯誤:語法錯誤」?
我收到此錯誤:
Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\photo_gallery\includes\functions.php on line 76
這裏是我的代碼,有什麼不好?
<?php
function strip_zeros_from_date($marked_string="") {
// first remove the marked zeros
$no_zeros = str_replace('*0', '', $marked_string);
// then remove any remaining marks
$cleaned_string = str_replace('*', '', $no_zeros);
return $cleaned_string;
}
function redirect_to($location = NULL) {
if ($location != NULL) {
header("Location: {$location}");
exit;
}
}
function output_message($message="") {
if (!empty($message)) {
return "<p class=\"message\">{$message}</p>";
} else {
return "";
}
}
function __autoload($class_name) {
$class_name = strtolower($class_name);
$path = LIB_PATH.DS."{$class_name}.php";
if(file_exists($path)) {
require_once($path);
} else {
die("The file {$class_name}.php could not be found.");
}
}
function include_layout($names, $args){
// allow for single file names
if (!is_array($names)) {
$names = array($names);
}
$found = false;
foreach ($names as $name) {
$file = siteroot.'/public/layouts/'.$name.'.php';
if (file_exists($file)) {
$found = $file;
break;
}
}
if (! $found) {
return '';
}
function log_action($action, $message="") {
$logfile = SITE_ROOT.DS.'logs'.DS.'log.txt';
$new = file_exists($logfile) ? false : true;
if($handle = fopen($logfile, 'a')) { // append
$timestamp = strftime("%Y-%m-%d %H:%M:%S", time());
$content = "{$timestamp} | {$action}: {$message}\n";
fwrite($handle, $content);
fclose($handle);
if($new) { chmod($logfile, 0755); }
} else {
echo "Could not open log file for writing.";
}
}
function datetime_to_text($datetime="") {
$unixdatetime = strtotime($datetime);
return strftime("%B %d, %Y at %I:%M %p", $unixdatetime);
}
?>
我使用的XAMPP在Windows 7上我一直在試圖找到一個解決辦法,但我不知道自己做錯了什麼。由於我添加了包括header.php
和footer.php
的函數方法,它開始給我那個錯誤。下面是我添加方法:
function include_layout($names, $args){
// allow for single file names
if (!is_array($names)) {
$names = array($names);
}
$found = false;
foreach ($names as $name) {
$file = siteroot.'/public/layouts/'.$name.'.php';
if (file_exists($file)) {
$found = $file;
break;
}
}
if (! $found) {
return '';
}
如果您安裝了一個IDE(例如NetBeans for PHP),那麼即使您不需要運行代碼,編輯窗口也會顯示語法錯誤。 – halfer