我在处理一段代码时遇到了这个错误。 解析错误:语法错误,第44行/admin.php中的意外T_CONSTANT_ENCAPSED_STRING 这是我的第一个PHP脚本,它工作正常,直到我改变它所以它将输入到PHP,现在它说这...如果它刚刚开始学习它的一个愚蠢的错误不要生气。第44行以$ filename
开头继承我的代码
<?php
if (!isset($_POST['submit'])) {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1- transitional.dtd">
<html>
<head>
<title>Micro News</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript" src="js/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
tinyMCE.init({
mode : "textareas",
theme : "advanced",
theme_advanced_buttons3 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
});
</script>
</head>
<body>
<div id="main">
<div id="caption">Micro News - Add news</div>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
News title:<br/>
<input type="text" name="title" size="40"/><br/><br/>
Content:<br/>
<textarea name="newstext" rows="15" cols="67"></textarea><br/>
<center><input type="submit" name="submit" value="Save" /></center>
</form>
<div id="source">Micro News 1.0</div>
</div>
</body>
<?php } else {
$newsTitel = isset($_POST['title']) ? $_POST['title'] : 'Untitled';
$submitDate = date('Y-m-d');
$newsContent = isset($_POST['newstext']) ? $_POST['newstext'] : 'No content';
$filename = ($newsTitel".php");
$f = fopen('news/'.$filename.);
fwrite($f,$newsTitel."\n");
fwrite($f,$submitDate."\n");
fwrite($f,$newsContent."\n");
fclose($f);
header('Location:index.php');
}
?>
答案 0 :(得分:1)
这是什么?
$filename = ($newsTitel".php");
你的意思是
$filename = $newsTitel . ".php";
// or
$filename = ($newsTitel . ".php");
答案 1 :(得分:1)
$filename = ($newsTitel".php");
它告诉你错误在这里。需要两秒钟才能注意到它应该是:
$filename = ($newsTitel.".php");
// missing dot here ---^