从URL获取表详细信息

时间:2015-05-05 08:02:12

标签: php html file-get-contents

我只想从HTML中获取表格详细信息,例如URL为

$url="https://www.centralbank.org.bz/rates-statistics/exchange-rates";

由此,我需要在此currency rate中获取url表,并删除所有dirty data

请帮帮我, 非常感谢

2 个答案:

答案 0 :(得分:0)

试试这段代码::

$url = 'https://www.centralbank.org.bz/rates-statistics/exchange-rates';
$content = file_get_contents($url);
$first_step = explode( '<table id="currencyTable">' , $content );
$second_step = explode("</table>" , $first_step[1] );

echo $second_step[0];

答案 1 :(得分:-1)

您应该使用Simple HTML DOM

示例可能对您有所帮助:

<?php

include('simple_html_dom.php');

$url = 'https://www.phpbb.com/community/viewtopic.php?f=46&t=543171';

$html = file_get_html($url);
$links = array();
foreach($html->find('a[class="postlink"]') as $a) {
 $links[] = $a->href;
}

print_r($links);

?>