tags:

views:

73

answers:

2

Sorry for the poor title guys, but I'm whooped. I have a table as such:

<table class="gsborder" cellspacing="0" cellpadding="2" rules="cols" border="1" id="d00">
        <tr class="gridItem">
                <td>Code</td><td>0adf</td>
        </tr><tr class="AltItem">
                <td>CompanyName</td><td>Some Company</td>
        </tr><tr class="Item">
                <td>Owner</td><td>Jim Jim</td>
        </tr><tr class="AltItem">
                <td>DivisionName</td><td> </td>
        </tr><tr class="Item">
                <td>AddressLine1</td><td>9314 W. SPRING ST.</td>
        </tr>
</table>

I'm using the following code to get my data out:

  $foo = $html->getElementById("d00")->childNodes(1)->childNodes(1);

The problem with this though is that I am getting the two <td></td> tags with my data. Is there a way to only grab the raw data without the tags?

Also, is this the right way to get my data out of this table?

+2  A: 

Use strip_tags to get raw text.

http://us.php.net/manual/en/function.strip-tags.php

So:

$foo = strip_tags($html->getElementById("d00")->childNodes(1)->childNodes(1));
Sbm007
ahh... Thanks Sbm.. Thank you!
+3  A: 

Try using:

$foo = $html->getElementById("d00")->childNodes(1)->childNodes(1)->plaintext;

or innertext.

// Example
$html = str_get_html("<div>foo <b>bar</b></div>"); 
$e = $html->find("div", 0);

echo $e->tag; // Returns: " div"
echo $e->outertext; // Returns: " <div>foo <b>bar</b></div>"
echo $e->innertext; // Returns: " foo <b>bar</b>"
echo $e->plaintext; // Returns: " foo bar"

taken from: http://simplehtmldom.sourceforge.net/manual.htm

As a rule of thumb, whatever DOM API you are using, once you've located the element(s) you are interested in getting data from, accessing the text nodes they contain requires a bit more work.

Andy
Oops.. I didn't see your answer yet Andrew. Thanks. I looked over the manual but I honestly had no idea this was what I needed. I am going to try this also.
Yep, I just tried that and that works as well. All I was missing was the ->plaintext. Andrew.. Thank you so much.