dongyun6229 2014-03-21 13:34
浏览 69
已采纳

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

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)

Here is my code on the html / php page

<?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">
\t';
        if ($ticket_link = true){
            echo '<a href="$ticket_link" onClick="return false;"> BOOK TICKETS </a>
';
        };
        echo '</span>

';                         
        echo '<span class="bottom">
\t';
        echo '<a href="$event_link" class="gig-tag" onClick="return false;">
\t\t';
        echo '<span class="when">$day \/ $month - $location</span>
\t\t';
        echo '<span class="where">$description</span>
\t';
        echo '</a>
';
        echo '</span>
';
    };
?>

</div>

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

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

  • 写回答

1条回答 默认 最新

  • dongyonglie5132 2014-03-21 13:37
    关注

    The following line of code is not valid in PHP versions prior to 5.5 (this means you are not using 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 (list($day, $month, $year, $location, $description, $event_link, $ticket_link) = each($gig)) {
    

    Or use extract() (not recommended):

    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
    
    $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',
            ''
        ),
    );
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题
  • ¥15 有没有人能解决下这个问题吗,本人不会编程
  • ¥15 plotBAPC画图出错
  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗