Frage

$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

War es hilfreich?

Lösung

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) );
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top