Search code examples
phphtmlsimple-html-dom

Simple HTML dom removing content from displayed


Trying to get all of the posts from my search page and display them as related search queries on the content page using simple_html_dom.

include('simple_html_dom.php');
$html = file_get_html('http://example.com/search.php?q=Song Artist - Song Name');
$html->find('div', 1)->class = 'media-body';
$html->find('div[class=media-body]', 0);
echo $html;

Currently this works but it includes the header of the page, and the footer of the page I only want the content within the div media-body to be printed as html

(I am also a new developer so I could be doing this completely wrong all together..)


Solution

  • According to library doc (http://simplehtmldom.sourceforge.net/manual.htm) if you want to get the content of any element you need to do this (for example):

    $ret = $html->find('div[class=media-body]');
    echo $res->innertext;
    

    links:

    1. http://simplehtmldom.sourceforge.net/manual.htm#container_find
    2. http://simplehtmldom.sourceforge.net/manual_api.htm