Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><em>Update: Should now work with OP's updated sample code.</em></p> <p>This should get you going:</p> <p><strong>table-array.php</strong></p> <pre><code>&lt;?php // SimpleHTMLDom Library require_once('lib/simple_html_dom.php'); // Source Data $source = 'table-array-data.htm'; // Displays Extra Debug Info $dbg = 1; // Read DOM $html = file_get_html($source); // Confirm DOM if ($html) { // Debug Output if ($dbg) { echo '&lt;pre&gt;'; } // Loop for each &lt;table&gt; foreach ($html-&gt;find('table') as $table) { // Debug Output if ($dbg) { echo 'TABLE' . PHP_EOL; } // Loop for each &lt;tr&gt; foreach ($table-&gt;find('tr') as $row) { // Debug Output if ($dbg) { echo ' ROW' . PHP_EOL; } // Loop for each &lt;th&gt; foreach ($row-&gt;find('th') as $cell) { // Look for &lt;a&gt; tag $link = $cell-&gt;find('a'); // Found a link if (count($link) == 1) { // Debug Output if ($dbg) { echo ' LINK: ' . $link[0]-&gt;innertext . ' (' . $link[0]-&gt;href . ')' . PHP_EOL; } } } // Loop for each &lt;td&gt; foreach ($row-&gt;find('td') as $cell) { // Debug Output if ($dbg) { echo ' CELL: ' . $cell-&gt;innertext . PHP_EOL; } } } } // Debug Output if ($dbg) { echo '&lt;/pre&gt;'; } } ?&gt; </code></pre> <hr> <p><strong>table_array_data.htm</strong></p> <pre><code>&lt;table&gt; &lt;tr class="first"&gt; &lt;th class="school first"&gt;&lt;a href="/local/team/home.aspx?schoolid=472d8593-9099-4925-81e0-ae97cae44e43&amp;amp"&gt;Aberdeen&lt;/a&gt;&lt;/th&gt; &lt;td class="mascot"&gt;Bulldogs&lt;/td&gt; &lt;td class="city"&gt;Aberdeen&lt;/td&gt; &lt;td class="state last"&gt;MS&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <hr> <p><strong>output</strong></p> <pre><code>TABLE ROW LINK: Aberdeen (/local/team/home.aspx?schoolid=472d8593-9099-4925-81e0-ae97cae44e43&amp;) CELL: Bulldogs CELL: Aberdeen CELL: MS </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload