$landings = file_get_contents('http://www.domain.co.uk/page.php');
在上面的示例网址中,我只想从特定元素#sidebar-bgbtm
中选择和复制HTML
从那里我想将HTML导出为JSON值。
有没有办法做到这一点?
由于
答案 0 :(得分:2)
如果您熟悉jQuery语法,PHP Simple HTML DOM可能是一个很好的起点 http://simplehtmldom.sourceforge.net/
include('simple_html_dom.php');
$html = file_get_html('http://www.domain.co.uk/page.php');
$result = $html->find('#sidebar-bgbtm', 0)->outertext;
然后导出到json:
echo json_encode( array( 'outertext' => $result) );