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

解析错误:语法错误,第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 matlab数字图像处理频率域滤波
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行