是什么导致意外的T_CONSTANT_ENCAPSED_STRING错误? [英] What causes unexpected T_CONSTANT_ENCAPSED_STRING error?
问题描述
我有一个简单的PHP脚本,不断抛出此奇怪的错误消息:
I have a simple PHP script that keeps throwing this bizarre error message:
解析错误:语法错误,/script.php中出现意外的'"string"(T_CONSTANT_ENCAPSED_STRING)
Parse error: syntax error, unexpected '"string' (T_CONSTANT_ENCAPSED_STRING) in /script.php
<?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问题中提到问题可能是CRLF行尾而不是CF,但是我不确定.
I saw somebody mention in another SO question that the issue might be CRLF line endings instead of CF, but I'm not sure.
推荐答案
好吧,我最终自己找到了解决方案,该错误是由于某些损坏的空格/换行符引起的,并且由于我不想遍历整个文件,我使用了那些工具:
Well, I ended up finding a solution myself, the error was due to some corrupt whitespace/linefeed characters, and since I didn't want to go through the entire file, I used those tools:
http://www.textfixer.com/tools/remove-line- breaks.php http://www.textfixer.com/tools/remove-white-spaces.php
这可以验证代码: http://phpcodechecker.com
这可以再次美化代码: http://www.cleancss.com/php-beautify/
And this to beautify the code again: http://www.cleancss.com/php-beautify/
确保在此过程之前删除所有单行注释.
这篇关于是什么导致意外的T_CONSTANT_ENCAPSED_STRING错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!