解析错误:语法错误,第12行/home/public_html/gigs.html中的意外T_LIST

时间:2020-12-08 22:34:49

I'm trying to build an events page for my band's website using PHP to list our upcoming gigs (I'm still quite new to server side script) And I keep getting the above error displaying on the page in browser. I'm sure there's something simple I'm missing / doing wrong but I can't seem to figure out what it is (I'm struggling to find relevant info online too)

我正在尝试使用PHP为我的乐队网站建立一个活动页面,列出我们即将到来的演出(我对服务器端脚本还很新)我一直在浏览器页面上显示上面的错误。我确信有一些简单的东西我错过了/做错了但我似乎无法弄清楚它是什么(我也在努力在网上找到相关信息)

Here is my code on the html / php page

这是我在html / php页面上的代码

<?php
$body_id = 'gigs'
?>

<?php include($_SERVER['DOCUMENT_ROOT'].'/fragments/html.html'); ?>

<div class="content-left">

    <?php
    include($_SERVER['DOCUMENT_ROOT'].'/php/arr_gigs.php');

    foreach ($gig as list($day, $month, $year, $location, $description, $event_link, $ticket_link)) {

        echo '<span class="top">\n\t';
        if ($ticket_link = true){
            echo '<a href="$ticket_link" onClick="return false;"> BOOK TICKETS </a>\n';
        };
        echo '</span>\n\n';                         
        echo '<span class="bottom">\n\t';
        echo '<a href="$event_link" class="gig-tag" onClick="return false;">\n\t\t';
        echo '<span class="when">$day \/ $month - $location</span>\n\t\t';
        echo '<span class="where">$description</span>\n\t';
        echo '</a>\n';
        echo '</span>\n';
    };
?>

</div>

And here is php/arr_gigs.php where I hope to put in all the gig details, date, location, links etc.

这里是php / arr_gigs.php,我希望在这里放入所有的演出细节,日期,地点,链接等。

<?php

$gig = [
[28,12,2013,
'The Firebug - Leicester', 
'with more awesome bands',
'www.facebook.com',
'www.seetickets.com'],

[19,04,2014,
'Pi Bar - Leicester', 
'(acts tbc)',
'www.facebook.com',
''],
];

?>

As far as I know I'm running the latest version of PHP (5.3 or similar) If there's any help or advice someone could give me I'd be really grateful :) Or if you think there's a better way I could achieve the desired effect

据我所知,我正在运行最新版本的PHP(5.3或类似版本)如果有任何帮助或建议,有人可以给我,我真的很感激:)或者如果你认为有更好的方法我可以实现所需影响

1 个解决方案

#1


1  

The following line of code is not valid in PHP versions prior to 5.5 (this means you are not using PHP 5.5):

以下代码行在5.5之前的PHP版本中无效(这意味着您不使用PHP 5.5):

foreach ($gig as list($day, $month, $year, $location, $description, $event_link, $ticket_link)) {

If you wish to get all of those values either use the array syntax to access them:

如果您希望获得所有这些值,请使用数组语法来访问它们:

foreach ($gig as $giginfo) {
    echo $giginfo['day'];

Or use a while loop:

或者使用while循环:

while (list($day, $month, $year, $location, $description, $event_link, $ticket_link) = each($gig)) {

Or use extract() (not recommended):

或者使用extract()(不推荐):

foreach ($gig as $giginfo) {
    extract($giginfo);

As for your array, you are using a syntax that is only available in PHP 5.4. So you will need to use array() syntax instead:

对于您的数组,您使用的语法仅在PHP 5.4中可用。所以你需要使用array()语法:

<?php

$gig = array(
    array(28,12,2013,
        'The Firebug - Leicester', 
        'with more awesome bands',
        'www.facebook.com',
        'www.seetickets.com'
    ),
    array(
        19,04,2014,
        'Pi Bar - Leicester', 
        '(acts tbc)',
        'www.facebook.com',
        ''
    ),
);

?>

#1


1  

The following line of code is not valid in PHP versions prior to 5.5 (this means you are not using PHP 5.5):

以下代码行在5.5之前的PHP版本中无效(这意味着您不使用PHP 5.5):

foreach ($gig as list($day, $month, $year, $location, $description, $event_link, $ticket_link)) {

If you wish to get all of those values either use the array syntax to access them:

如果您希望获得所有这些值,请使用数组语法来访问它们:

foreach ($gig as $giginfo) {
    echo $giginfo['day'];

Or use a while loop:

或者使用while循环:

while (list($day, $month, $year, $location, $description, $event_link, $ticket_link) = each($gig)) {

Or use extract() (not recommended):

或者使用extract()(不推荐):

foreach ($gig as $giginfo) {
    extract($giginfo);

As for your array, you are using a syntax that is only available in PHP 5.4. So you will need to use array() syntax instead:

对于您的数组,您使用的语法仅在PHP 5.4中可用。所以你需要使用array()语法:

<?php

$gig = array(
    array(28,12,2013,
        'The Firebug - Leicester', 
        'with more awesome bands',
        'www.facebook.com',
        'www.seetickets.com'
    ),
    array(
        19,04,2014,
        'Pi Bar - Leicester', 
        '(acts tbc)',
        'www.facebook.com',
        ''
    ),
);

?>