문제

$landings = file_get_contents('http://www.domain.co.uk/page.php');

In the above example URL I want to only select and copy the HTML from a specific element #sidebar-bgbtm

From there I would like to export the HTML as a JSON value.

Is there any way of doing that?

Thanks

도움이 되었습니까?

해결책

If you are familiar with jQuery syntax, PHP Simple HTML DOM might be good place to start 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;

And then export to json:

echo json_encode( array( 'outertext' => $result) );
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top