0

Possible Duplicate:
How to parse and process HTML/XML with PHP?
how to scrape this with Simple HTML DOM

I have a table text like this:

$html='<table class="table1"><caption>Report</caption><tbody><tr> 
                    <th>#</th> 
                    <th>Date</th> 
                    <th>tablehead</th> 
                    <th>Price</th>
                    <th>Quantity</th>
                    <th>Total Amount</th>
                        </tr><tr class="even"><td>10</td>
                        <td>2013-01-19</td> 
                        <td>somevalue</td> 
                        <td>500</td> 
                        <td>17</td> 
                        <td>8500</td> 
                        </tr><tr> 
                    <th colspan="4">&nbsp;</th> 
                    <th>402</th>
                    <th>196700</th> 
                </tr> </tbody></table>';

I want to know how can I get the colspan value(when exists)? I am trying to use simple html dom but failed to get it. Any help will be appreciated.

Community
  • 1
  • 1
  • like you get [any other element attribute with SimpleHtmlDom](http://simplehtmldom.sourceforge.net/manual.htm#section_access) – Gordon Jan 19 '13 at 11:40
  • 1
    Use [`DOMDocument`](http://php.net/manual/en/class.domdocument.php) and [`DOMXPath`](http://php.net/manual/en/class.domxpath.php) instead and search for attribute `@colspan` – Havelock Jan 19 '13 at 11:41
  • @Havelock simplehtmldom does not support XPath – Gordon Jan 19 '13 at 11:42
  • @Gordon I missed that bit :-/ – Havelock Jan 19 '13 at 11:43
  • @Gordon Sorry, I saw that but I did not notice that there is th instead of td in my text. That's why I could not get the colspan value. Additional question, can I anyhow replace all th into td including , or , or – user1416016 Jan 19 '13 at 12:04
  • 1
    @user1416016 please do research before asking questions. You agreed to do so when you checked the checkbox at http://stackoverflow.com/questions/ask-advice. How to replace a node with SimpleHtmlDom has been asked and answered before. – Gordon Jan 19 '13 at 12:08

0 Answers0