Domanda

$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

È stato utile?

Soluzione

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) );
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top