Php 语法错误:意外的“[”,我做错了什么?

Php 语法错误:意外的“[”,我做错了什么?,php,html,dom,Php,Html,Dom,有趣的是,我一直在通过localhost在我的计算机上处理这个问题。它工作得非常好。然后我复制了相同的代码到GoDaddy,突然它不工作了 这是我的密码: <?php include ('simple_html_dom.php'); $html = file_get_html('http://www.tibia.com/community/?subtopic=worlds&world=Aurora'); $table = $html->find('table[class=

有趣的是,我一直在通过localhost在我的计算机上处理这个问题。它工作得非常好。然后我复制了相同的代码到GoDaddy,突然它不工作了

这是我的密码:

<?php

include ('simple_html_dom.php');

$html = file_get_html('http://www.tibia.com/community/?subtopic=worlds&world=Aurora');
$table = $html->find('table[class=Table2]')[0];

for ($i = 0; $i < 20; $i++)
{
    $player = $table->find('tr[class=Even]')[$i]->find('a')[0];
    echo $player->href . '<br>';
    $html2 = file_get_html($player->href);
    $date = $html2->find('[@id="characters"]/div[5]/div/div/table[3]/tbody/tr[2]/td[1]')[0];
    echo $date . '<br>';
    $dateArr = explode(" ", $date);
    echo $dateArr . '<br>';
    echo count($dateArr[0]);
    //for ($k = 0; count($dateArr[0]); $k++)
    //{
    //  echo $dateArr[0][$k] . '<br>';
    //}
}

?>
下面是确切的错误:

分析错误:语法错误,中出现意外的“[” /第6行的home/content/27/11250627/html/tibia/pvplist.php


看一下关于阵列的手册:具体看一下示例7

它说:

// on PHP 5.4
$secondElement = getArray()[1];

// previously
$tmp = getArray();
$secondElement = $tmp[1];
所以你需要做:

$table = $html->find('table[class=Table2]'); 
$table = $table[0] 

仅在PHP5.4中添加了取消引用doSomething[someindex]的奇特名称的函数

您使用的是旧版本

$tables = $html->find("table[class=2]");
$table = $tables[0];

请尝试使用双引号。另外,find方法中有什么?您正在运行哪个php版本?函数调用后的数组解引用仅在PHP5.4之后有效。