Getting DOM elements of html from file_get_contents
<p>I am fetching html from a website with <code>file_get_contents</code>. I have a table (with a class name) inside html, and I want to get the data inside html tags. </p>

<p>This is how I fetch the html data from url:</p>

<pre><code>$url = 'http://example.com';
$content = file_get_contents($url);
</code></pre>

<p>The html looks like:</p>

<pre><code>&lt;table class="space"&gt;
   &lt;thead&gt;&lt;/thead&gt;
   &lt;tbody&gt;
      &lt;tr&gt;
         &lt;td class="marsia"&gt;1&lt;/td&gt;
         &lt;td class="mars"&gt;
           &lt;div&gt;Mars&lt;/div&gt;
         &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
         &lt;td class="earthia"&gt;2&lt;/td&gt;
         &lt;td class="earth"&gt;
           &lt;div&gt;Earth&lt;/div&gt;
         &lt;/td&gt;
      &lt;/tr&gt;
   &lt;/body&gt;
&lt;/table&gt;
</code></pre>

<p>Is there a way to searh DOM elements in php like we do in jQuery? So that I can access the values 1, 2 (first td) and div's value inside second td.</p>

<p>Something like</p>

<p>a) search the html for table with class name space</p>

<p>b) inside that table, inside tbody, return each tr's 'first td's value' and 'div's value inside second td' </p>

<p>So I get; 1 and Mars, 2 and Earth.</p>