我尝试了很多解决方案,但它确实有所帮助。我甚至尝试打开short_tags_on但没有解决方案。
我收到此错误:
解析错误:语法错误,文件意外结束 第76行的C:\ xampp \ htdocs \ photo_gallery \ includes \ functions.php
这是我的代码,出了什么问题?
<?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);
}
?>
我在Windows 7上使用xampp。我一直在努力寻找解决方案,但我不知道出了什么问题。由于我添加了包含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 '';
}
答案 0 :(得分:1)
您没有关闭include_layout函数,它错过了最后的}
。
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 '';
}
} // << missing from your code