【问题标题】:What causes unexpected T_CONSTANT_ENCAPSED_STRING error? [duplicate]是什么导致意外的 T_CONSTANT_ENCAPSED_STRING 错误? [复制]
【发布时间】: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 标签 (?&gt;)。它们毫无用处,而且一直在制造麻烦。
  • 从 PHP Parse/Syntax Errors 中读取答案,删除 ?&gt;,没有变化。
  • @u_mulder 在您提到的答案中,只提到了简单的拼写错误等(不正确的连线,混合使用引号等),我没有找到任何对我有帮助的东西,也许你会指出来的。

标签: php apache


【解决方案1】:

好吧,我最终自己找到了解决方案,错误是由于一些损坏的空白/换行字符造成的,并且由于我不想浏览整个文件,所以我使用了这些工具:

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/

确保在此过程之前删除所有单行 cmets。

【讨论】:

    猜你喜欢
    • 2016-02-29
    • 1970-01-01
    • 2015-01-23
    • 1970-01-01
    • 2012-03-10
    • 2021-12-19
    • 1970-01-01
    • 2014-02-25
    相关资源
    最近更新 更多