Вопрос

$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