【发布时间】:2016-04-30 03:05:20
【问题描述】:
我有一个简单的 PHP 脚本,它不断抛出这个奇怪的错误消息:
解析错误:语法错误,/script.php 中出现意外的 '"string' (T_CONSTANT_ENCAPSED_STRING)
<?php
error_reporting(-1);
require_once "PHPMailer/PHPMailerAutoload.php";
$api_key = "string"; // this line causes the error
$payload = file_get_contents("php://input");
$new_booking = json_decode($payload, true);
$schedule_id = "123456";
$schedule_link = "http://example.com";
$passwd = "passwd";
// email config
$admin = [
"name" => "Joe White",
"user" => "user@gmail.com",
"passwd" => "passwd"
];
$max_time = 3; // hours
$max_dist = 200; // miles
/*
Code goes on, but is commented out and therefore not included here
*/
?>
我看到有人在另一个 SO question 中提到问题可能是 CRLF 行结尾而不是 CF,但我不确定。
【问题讨论】:
-
错误信息告诉你这个错误在哪一行?
-
您是否显示了该特定行的代码?
-
停止在文件末尾使用关闭 php 标签 (
?>)。它们毫无用处,而且一直在制造麻烦。 -
从 PHP Parse/Syntax Errors 中读取答案,删除
?>,没有变化。 -
@u_mulder 在您提到的答案中,只提到了简单的拼写错误等(不正确的连线,混合使用引号等),我没有找到任何对我有帮助的东西,也许你会指出来的。