有趣的是,我一直在我的计算机上通过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>';
//}
}
?>
Run Code Online (Sandbox Code Playgroud)
这是确切的错误:
解析错误:语法错误,第6行的/home/content/27/11250627/html/tibia/pvplist.php中的意外'['
看一下阵列手册:http://www.php.net/manual/en/language.types.array.php具体看一下例7.
它说:
// on PHP 5.4
$secondElement = getArray()[1];
// previously
$tmp = getArray();
$secondElement = $tmp[1];
Run Code Online (Sandbox Code Playgroud)
所以你需要这样做:
$table = $html->find('table[class=Table2]');
$table = $table[0]
Run Code Online (Sandbox Code Playgroud)