0

The funny thing is, I've been working on this on my computer through localhost. It works perfectly fine. Then I copied the same exact code to GoDaddy and suddenly it doesn't work.

Here is my code:

<?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>';
    //}
}

?>

Here is the exact error:

Parse error: syntax error, unexpected '[' in /home/content/27/11250627/html/tibia/pvplist.php on line 6

Evan
  • 2,405
  • 3
  • 20
  • 24

2 Answers2

4

Take a look at the manual on arrays: http://www.php.net/manual/en/language.types.array.php Specifically look at example 7.

It says that:

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

// previously
$tmp = getArray();
$secondElement = $tmp[1];

So you need to do:

$table = $html->find('table[class=Table2]'); 
$table = $table[0] 
Ryan
  • 14,392
  • 8
  • 62
  • 102
3

Function dereferencing (the fancy name for doSomething()[someindex]) was only added in PHP 5.4.

You're using an older version.

$tables = $html->find("table[class=2]");
$table = $tables[0];
Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592