Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用PHP解析HTML表_Php_Html_Parsing_Dom_Simple Html Dom - Fatal编程技术网

用PHP解析HTML表

用PHP解析HTML表,php,html,parsing,dom,simple-html-dom,Php,Html,Parsing,Dom,Simple Html Dom,我一直在尝试使用不同的工具在站点上解析底部的表 到目前为止,我在使用简单的HTMLDOM库方面取得了最大的成功,但我仍然不知道如何只解析最后一个表 到目前为止,我的代码大致如下: <?php require('simple_html_dom.php'); $table = array(); $html = file_get_html('http://www.waterlevels.gc.ca/cgi-bin/tide-shc.cgi?zone=20&region=1&

我一直在尝试使用不同的工具在站点上解析底部的表

到目前为止,我在使用简单的HTMLDOM库方面取得了最大的成功,但我仍然不知道如何只解析最后一个表

到目前为止,我的代码大致如下:

<?php

require('simple_html_dom.php');

$table = array();

$html = file_get_html('http://www.waterlevels.gc.ca/cgi-bin/tide-shc.cgi?zone=20&region=1&   language=english&station=9635&queryType=predict&year=2012&month=2&day=9&view=table&TZ=PST');

foreach($html->find('tr') as $row) 
{
//confused as what to do there to parse only last table in given URL
}

echo '<pre>';
print_r($table);
echo '</pre>';

?>

如果有人对如何让库只解析最后一个表有任何建议,我们将不胜感激


谢谢

您可以在
find()
调用中使用负数来获取特定元素。这将得到倒数第二个表,其中包含所有数据:

$ret = $html->find('tr', 0);

您可以在
find()
调用中使用负数来获取特定元素。这将得到倒数第二个表,其中包含所有数据:

$ret = $html->find('tr', 0);

您应该能够使用以下内容:


只需将
0
替换为正确的#

您应该能够使用以下内容:

只需将
0
替换为正确的#