Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I suppose you want to parse a HTML document using PHP. I suggest you read about the <a href="http://www.php.net/manual/en/book.dom.php" rel="nofollow noreferrer"><a href="http://www.php.net/manual/en/book.dom.php" rel="nofollow noreferrer">http://www.php.net/manual/en/book.dom.php</a></a></p> <p>Here is an example provided by <a href="http://www.phpro.org/examples/Parse-HTML-With-PHP-And-DOM.html" rel="nofollow noreferrer">PHP Pro</a></p> <pre><code>&lt;?php $html = ' &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" dir="ltr"&gt; &lt;head&gt; &lt;title&gt;PHPRO.ORG&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h2&gt;Forecast for Saturday&lt;/h2&gt; &lt;!-- Issued at 0828 UTC Friday 23 May 2008 --&gt; &lt;table border="0" summary="Capital Cities Precis Forecast"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;a href="/products/IDN10064.shtml" title="Link to Sydney forecast"&gt;Sydney&lt;/a&gt;&lt;/td&gt; &lt;td title="Maximum temperature in degrees Celsius" class="max alignright"&gt;19&amp;deg;&lt;/td&gt; &lt;td&gt;Fine. Mostly sunny.&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;a href="/products/IDV10450.shtml" title="Link to Melbourne forecast"&gt;Melbourne&lt;/a&gt;&lt;/td&gt; &lt;td title="Maximum temperature in degrees Celsius" class="max alignright"&gt;16&amp;deg;&lt;/td&gt; &lt;td&gt;Fog then fine.&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;a href="/products/IDQ10095.shtml" title="Link to Brisbane forecast"&gt;Brisbane&lt;/a&gt;&lt;/td&gt; &lt;td title="Maximum temperature in degrees Celsius" class="max alignright"&gt;24&amp;deg;&lt;/td&gt; &lt;td&gt;Mostly fine&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;a href="/products/IDW12300.shtml" title="Link to Perth forecast"&gt;Perth&lt;/a&gt;&lt;/td&gt; &lt;td title="Maximum temperature in degrees Celsius" class="max alignright"&gt;21&amp;deg;&lt;/td&gt; &lt;td&gt;Few showers, increasing later.&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;a href="/products/IDS10034.shtml" title="Link to Adelaide forecast"&gt;Adelaide&lt;/a&gt;&lt;/td&gt; &lt;td title="Maximum temperature in degrees Celsius" class="max alignright"&gt;20&amp;deg;&lt;/td&gt; &lt;td&gt;Fine. Mostly sunny.&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;a href="/products/IDT65061.shtml" title="Link to Hobart forecast"&gt;Hobart&lt;/a&gt;&lt;/td&gt; &lt;td title="Maximum temperature in degrees Celsius" class="max alignright"&gt;13&amp;deg;&lt;/td&gt; &lt;td&gt;Mainly fine.&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;a href="/products/IDN10035.shtml" title="Link to Canberra forecast"&gt;Canberra&lt;/a&gt;&lt;/td&gt; &lt;td title="Maximum temperature in degrees Celsius" class="max alignright"&gt;15&amp;deg;&lt;/td&gt; &lt;td&gt;Fine, mostly sunny.&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;a href="/products/IDD10150.shtml" title="Link to Darwin forecast"&gt;Darwin&lt;/a&gt;&lt;/td&gt; &lt;td title="Maximum temperature in degrees Celsius" class="max alignright"&gt;32&amp;deg;&lt;/td&gt; &lt;td&gt;Fine and sunny.&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; '; /*** a new dom object ***/ $dom = new domDocument; /*** load the html into the object ***/ $dom-&gt;loadHTML($html); /*** discard white space ***/ $dom-&gt;preserveWhiteSpace = false; /*** the table by its tag name ***/ $tables = $dom-&gt;getElementsByTagName('table'); /*** get all rows from the table ***/ $rows = $tables-&gt;item(0)-&gt;getElementsByTagName('tr'); /*** loop over the table rows ***/ foreach ($rows as $row) { /*** get each column by tag name ***/ $cols = $row-&gt;getElementsByTagName('td'); /*** echo the values ***/ echo $cols-&gt;item(0)-&gt;nodeValue.'&lt;br /&gt;'; echo $cols-&gt;item(1)-&gt;nodeValue.'&lt;br /&gt;'; echo $cols-&gt;item(2)-&gt;nodeValue; echo '&lt;hr /&gt;'; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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