Jump to content

Using fetchbody in loadHTML


Recommended Posts

Hi all

 

I'm managing to get the HTML content from an email body using

$html = quoted_printable_decode(imap_fetchbody($inbox,$email_number,1));

and when I print $html it displays the correct email html code.

 

But when I try and use it (line 2)

$doc = new DOMDocument();
$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
$tables = $doc->getElementsByTagName('table');

$nodes  = $xpath->query('.//tbody/tr/td', $tables->item(5));
print $nodes->item(3)->nodeValue;

I get the error

 

Notice: Trying to get property of non-object

 

Do I need to clean up the $html variable before it can be used?

 

Thanks for any advice

Link to comment
Share on other sites

What property? What non-object? We need the actual line, not just the error message.

 

You have a total lack of error handling, so that's likely the reason for the notice. You cannot just assume that all HTML selectors and queries will yield a non-empty result. You have to actually check that before you can start processing the result.

 

It's also time to learn basic debugging skills like inspecting variables with var_dump(). We can speculate all day long about what might be wrong, but if you want a definite answer, you have to analyze the data and control flow.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.