PHP解析错误:语法错误,意外的'const'(T_CONST),期待','或';'使用JavaScript时

时间:2018-04-07 14:35:45

标签: javascript php jquery html parsing

我的PHP脚本连接到多个Raspberry PI,这些PI都具有以下格式的CSV文件:

2018-03-22 12:43:21,NM_Test.h264,-2

然后我获取多个CSV文件并将其显示为HTML表格:

<?php
require_once 'Net/SSH2.php';
require_once 'phpseclib1.0.10/Crypt/RSA.php';
//when you include/require like this it puts the content into the variable
//when that content is a PHP array, it puts it in the variable. This needs to be included each time the script is ran
$config = require 'config.php';
$log = 'logfile.txt';

if(is_array($config)){
 foreach($config as $cred){
    $ssh = new Net_SSH2($cred['ip'], $cred['port']); //i think this is port?
    $key = new Crypt_RSA();
    $key->loadKey($cred['key']);

    if (!$ssh->login('pi', $key)){
         //logging with file_put_contants, Append mode, exclusive lock is more race condition safe then an open file handle.
        file_put_contents($log, "[".date('Y-m-d H:i:s')."]Login Failed for {$cred['ip']}\n", FILE_APPEND|LOCK_EX);
        continue;
        //or you can echo it, but you don't want to kill the whole thing if one fails /maybe?
    }
    //echo or save to file etc.
    $output = $ssh->exec('tail -1 /var/log/playlog.csv');

    };

echo"<script language='javascript'>

define('data', '$output');

function circle(errorStatus) { return $('<span>').css('color', errorStatus == '0' ? "#7d3" : "red").text('⚫');

const columnNames = ['Status', 'Date/Time', 'Video', 'Error Status'];

const head = $('<thead>').append($("<tr>").append(columnNames.map(h =>
$('<th>').text(h))));
}
const body = $("<tbody>").append(data.split("\n").map(row => {
const cdata = row.split(",");
const columns = [circle(cdata[2]), ...cdata].map(c => $('<td>').html(c));
return $("<tr>").append(columns);
}));

const table = $("<table>").addClass("table table- 
striped").append(head).append(body);

$('#container').append(table);
</script>
";
?>

但是,当我运行脚本时,我收到以下语法错误:

PHP Parse错误:语法错误,意外'const'(T_CONST),期待','或';'

在这一行:

const columnNames = ['Status', 'Date/Time', 'Video', 'Error Status'];

我该如何解决这个问题?

0 个答案:

没有答案