use*_*462 -3 php file-get-contents
我试图在另一个网站上显示一个网站的内容.这就是我目前拥有的:
<?php
$file = file_get_contents ('http://linkto.com/the-page');
echo $file;
?>
Run Code Online (Sandbox Code Playgroud)
它从该页面获取所有内容.但是,我只需要从中获取一个表.我基本上只需要从所有的内容<table id=arc>,以</table>.
有没有简单的方法来编辑我的代码才能获得该表?
这是使用PHP的本机DOM解析器的解决方案,DOMDocument:
$doc = new DOMDocument;
$doc->loadHTMLFile( 'http://linkto.com/the-page');
// Get the desired table
$table = $doc->getElementById( 'arc');
// Print the table's HTML
echo $doc->saveHTML( $table);
Run Code Online (Sandbox Code Playgroud)