-2

I have a simple PHP script that keeps throwing this bizarre error message:

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
    */
    ?>

I saw somebody mention in another SO question that the issue might be CRLF line endings instead of CF, but I'm not sure.

Pancake_M0nster
  • 267
  • 5
  • 18

1 Answers1

0

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

This to verify the code: http://phpcodechecker.com

And this to beautify the code again: http://www.cleancss.com/php-beautify/

Make sure you remove all single line comments before the process.

Pancake_M0nster
  • 267
  • 5
  • 18